Excel 2013 access violation 0xC0000005 - c++

I have a problem with an old piece of software (early 2000) written in C++ that uses Excel for processing data. It worked fine in previous versions of Excel but since version 2013, I get a crash that I haven't seen before.
We have created our own COM add-in for Excel, this add-in is registered with regsvr32 and available in Excel 2013. The add-in refused to work at first but disabling Data Execution Prevention (DEP) got it working.
This add-in is accessed by creating an instance of Excel in code:
_Application.CreateDispatch ("Excel.Application");
After creating the instance of Excel we get the loaded add-ins from the instance and find our add-in by looping through the COM add-ins.
_Application.GetCOMAddIns();
Once we got our add-in we can send commands through the interface:
IExcelServer* server = excel.GetServerAddIn(); // Obtain the server COM-AddIn.
HRESULT result = server->Execute (&req, &rep, &retval);
One of the commands we can send here is requesting a value from Excel based on a given string label (the label will be in column A and this function returns the value in column B on the same row). Now the code crashes on the following line of code:
rng.Find (COleVariant (label), CovOptional, CovOptional, COleVariant (xlWhole), CovOptional, xlSearchNext, CovOptional, CovOptional, CovOptional);
The 'rng' object is of type Range and is from the correct sheet and the range goes from A1 to A17. When we get the value from 'rng' object (rng.GetValue2()) it gives us the following array (which contains the value that is specified in the label argument):
safearray of VARIANT = [1,17](Empty,Empty,BSTR = 0x160bc6bc "Web",Empty,Empty,Empty,Empty,BSTR = 0x0bbca5cc "Pre",BSTR = 0x15f499fc "WebStart",BSTR = 0x0bbca48c "WebMid",BSTR = 0x0bbca5a4 "WebEnd",BSTR = 0x160bc80c "Post",Empty,Empty,BSTR = 0x15f49a24 "SafeStartWeb",BSTR = 0x15f49a4c "SafeEndWeb",Empty)
We receive the following error while debugging:
"Unhandled Exception at 0x00ccbb4A in Excel.exe: 0xC0000005: Access violation reading location 0x00000000."
We also see the following message in the windows event viewer every time that Excel crashes:
"The description for Event ID 0 from source MSOIDSVC.EXE cannot be found. Either the component that raises this event is not installed on your local computer or the installation is corrupted. You can install or repair the component on the local computer.
If the event originated on another computer, the display information had to be saved with the event.
The following information was included with the event:
InitializeSvcAPI failed with hr = 0x8004888d"
The code is made in VS2010 using C++ and running Windows7 x64. We have also tested the code on a Windows8 x64 machine but we got the same result.
Has someone seen this crash before or can advise how to fix it?
Thanks in advance.

Related

Get text for error code returned by Poco?

I have an App with a Poco module for internet connection to support users with legacy XP and Vista OS connecting with TLS1.2. There is a connection problem that returns a Poco error code but I don't know what that means. Here is part of the logging output:
poco_connection::end_receiving_response_body entered
poco_connection::close entered
poco_session::destroy_connection entered
poco_connection::end_transaction entered (code 0x00280166, hresult 0x00000000, closing: FALSE)
--------- 043d7450 (Closing request)
poco_connection::transaction_notify entered (code 0x00280166, hresult 0x00000000): Status: 3
Poco Communication Failed: code 0x00280166, hresult 0x00000000
poco_connection::~poco_connection entered
A little research shows there is a class Poco::Error that includes a method
static std::string getMessage(
int errorCode
);
which returns a text string for errors. Unfortunately I don't have source for the Poco module and so I can't add that translation call.
Since Poco is an open source project, can anyone point me to a code location where I can look up the mapping of Poco errors? Specifically error code 0x00280166
Seems I got lucky with a bit of googling
https://github.com/pocoproject/poco/blob/develop/Foundation/src/Error.cpp
But I don't think you're in luck, the code just assumes the error code is a windows system error code. And when I google 0x00280166 this page is the only hit.

Using "rundll32.exe" to access SpeechUX.dll

Good Day,
I have searched the Internet tirelessly trying to find an example of how to start Windows Speech Training from with in my VB.Net Speech Recognition Application.
I have found a couple examples, which I can not get working to save my life.
One such example is on the Visual Studios Fourms:
HERE
this particular example users the "Process.Start" call to try and start the Speech Training Session. However this does not work for me. Here is the exmaple from that thread:
Process.Start("rundll32.exe", "C:\Windows\system32\speech\speechux\SpeechUX.dll, RunWizard UserTraining")
What happens is I get and error that says:
There was a problem starting
C:\Windows\system32\speech\speechux\SpeechUX.dll
The specified module could not be found
So I tried creating a shortcut (.lnk) file and thought I could access the DLL this way. My short cut kind of does the same thing. In the short cut I call the "rundll32.exe" with parameters:
C:\Windows\System32\rundll32.exe "C:\Windows\system32\speech\speechux\SpeechUX.dll" RunWizard UserTraining
Then in my VB.Net application I use the "Process.Start" and try to run the shortcut.
This also gives me the same error. However the shortcut itself will start the SPeech Training session. Weird?!?
So, I then took it one step further, to see if it has something to do with my VB.Net Application and the "Process.Start" Call.
I created a VBScript, and using "Wscript.Shell" I point to the Shortcut.
Running the VBScript calls the Shortcut and low and behold the Speech Training starts!
Great! But...
when I try to run the VBscript from my VB.net Application, I get that error again.
What the heck is going on here?
Your problem likely is that your program is compiled as 32-bit and your OS is 64-bit, and thus, when you try to access "C:\Windows\System32\Speech\SpeechUX\SpeechUX.dll" from your program, you're really accessing "C:\Windows\SysWOW64\Speech\SpeechUX\SpeechUX.dll" which, as rundll32.exe is reporting doesn't exist.
Compile your program as 64-bit instead or try the pseudo directory %SystemRoot%\sysnative.
Also, instead of rundll32.exe, you may want to just run SpeechUXWiz.exe with an argument.
Eg.
private Process StartSpeechMicrophoneTraining()
{
Process process = new Process();
process.StartInfo.FileName = System.IO.Path.Combine(Environment.SystemDirectory, "speech\\speechux\\SpeechUXWiz.exe");
process.StartInfo.Arguments = "MicTraining";
process.Start();
return process;
}
private Process StartSpeechUserTraining()
{
Process process = new Process();
process.StartInfo.FileName = System.IO.Path.Combine(Environment.SystemDirectory, "speech\\speechux\\SpeechUXWiz.exe");
process.StartInfo.Arguments = "UserTraining";
process.Start();
return process;
}
Hope that helps.
Read more about Windows 32-bit on Windows 64-bit at http://en.wikipedia.org/wiki/WoW64
or your problem specifically at http://en.wikipedia.org/wiki/WoW64#Registry_and_file_system
If you are using a 64bit OS and want to access system32 folder you must use the directory alias name, which is "sysnative".
"C:\windows\sysnative" will allow you access to system32 folder and all it's contents.
Honestly, who decided this at Microsoft is just silly!!

Interop exception with VC++ and MySQL C++ Connector

I am helping a friend with his bachelor thesis project. It is a program that calculates bending moments for various materials. One of the extra requirements that the client desires is database functionality to store and retrieve various pieces of data being used in the program.
The program is a forms application written in managed C++. I jumped on board to help with writing the database functionality. I am using MySQL Server 5.5 and the MySQL Connector/C++ to bridge the program and the database. Everything has been going pretty well and all the functionality we need works just fine, but only in debug. As soon as we put the program into release mode there is undefined behavior occurring at runtime. Below is the function that is used to open a connection to the database:
try
{
m_driver = get_driver_instance();
m_conn = m_driver->connect(m_dbHost, m_dbUser, m_dbPwd);
m_conn->setSchema(m_dbSchema);
}
catch(sql::SQLException &e)
{
int a = e.getErrorCode();
MessageBoxA(NULL, e.what(), "DB Error", MB_OK);
}
The values passed into the connect function are all std::string. In debug mode the connection is made with no issues. In release mode an exception is caught after the connect function is called, and displays the message "Unknown MySQL Server Host '####' (0)" where the #### is always some garbage text. I also notice that in the output window another exception is being thrown, this one is the type System.Runtime.InteropServices.SEHException.
I have been doing some research and have seen numerous cases of this exception on many forums (and here on stack exchange) but no one seems to be having this issue with the MySQL connector. My assumption is that the memory is being corrupted because the program is mixed mode, with the main program code being written in Managed C++ and my database helper code being in native C++ (as required by the connector).
Is there something I can change in my code to try and fix this issue to that the strings aren't being corrupted at run time. I have tried many different hacks to try and solve the problem but nothing has worked.
Thanks,
Tom
Update: I am now seeing this error in debug mode. I added code to retrieve values from the database and populate some text boxes on the form. The code is as follows:
// Populate the form with material details
String^ selectedMaterial = (String^)(comboBox1->SelectedItem);
string selectedMaterial_ = "";
MarshalString(selectedMaterial, selectedMaterial_);
sql::ResultSet* results = dbHelper.GetData("matname", selectedMaterial_);
if (results->rowsCount() == 1)
{
// Outdim
string outdim_ = "";
outdim_ = results->getString("outdim");
String^ outdim = gcnew String(outdim_.c_str());
textBox1->Text = outdim;
}
else
{
// !!!! Duplicate materials in list
}
When it tries to read outdim from the result set the SEHException is thrown, and the only other piece of information given is that it was thrown in an external component.
Update 2: I ran Application Verifier against the debug executable and then launched the program from VS2010. However the form window never loads so somewhere along the line the program must be getting halted. Strangely there is absolutely no information in the log files in Application Verifier. I also tried with the release version and I didnt get any useful information from that either.

Task Scheduler 1.0: What does this error mean

I am working with the windows Task Scheduler 1.0 in win32 c++ & I am attempting to create & save a new task. Everything goes fine until I go to save the task by using the following function:
IPersistFile :: Save( NULL, TRUE );
The error that is returned is 0x8007052e
I have search & searched msdn but I cannot find a defintion for this error. Do you know that the HRESULT error with the value 0x8007052e means?
Some other info that might be important. I am using Windows 7, using a admin user & attempting to schedule a Daily task/trigger.
Using Visual Studios Error Lookup tool I find that it means "Logon failure: unknown user name or bad password. "
In fact, just Googling for that error code returns exactly the same information.
The HRESULT code 0x8007052e is very easy to decode. It consist from three parts
8xxxxxxx - means failure (error)
x007xxxx - means the facility 7
xxxx052e - meane the error code 0x52e=1326
If you open the WinError.h file you will easy find that FACILITY_WIN32 is 7.
So you have just a standard Win32 error with the code 0x52e=1326. If you search in WinError.h for 1326 you will find ERROR_LOGON_FAILURE with the description
Logon failure: unknown user name or
bad password.

How do I read boot time events on Windows 7?

I am trying to use the ETW functions without success to read the file:
C:\Windows\System32\winevt\Logs\Microsoft-Windows-Diagnostics-Performance%4Operational.evtx
In order to capture boot time events.
I have tried various functions -
OpenTrace gives an error 161
EvtQuery gives an error 15000
Does anyone have a native code example of reading system trace files?
I got this working as follows -
LPWSTR pwsPath = L"Microsoft-Windows-Diagnostics-Performance/Operational";
LPWSTR pwsQuery = L"Event/System[EventID=100]";
hResults = EvtQuery(NULL, pwsPath, pwsQuery,
EvtQueryChannelPath | EvtQueryReverseDirection);
The channel name can be found by going to Properties on an eventlog and using it's Full Name.
The error 15000 was due to me trying to open the log file with the given flags rather than the channel name.