Click here to Skip to main content
15,892,537 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I Created a 64 bit exe and 32 bit com dll ... i did neccesary changes in registry as suggested by some site ..

now CoCreateInstance is returning :

HRESULT_FROM_WIN32(ERROR_BAD_EXE_FORMAT) : %1 is not a valid Win32 application. HRESULT


Could you please let me know why the error came which is mentioned above.

What I have tried:

C++
int _tmain(int argc, _TCHAR* argv[])
{
	ICMATHCAUCULATOR *pMathcalci = nullptr;
	HRESULT hr;
	CoInitialize(NULL);
	hr = CoCreateInstance(CLSID_CMATHCAUCULATOR, NULL, CLSCTX_LOCAL_SERVER, IID_ICMATHCAUCULATOR, (void**)&pMathcalci);


	if (SUCCEEDED(hr))
	{
		cout << "function is called" << endl;
		double drresult = 0.0;
		pMathcalci->SumofTowNumbers(10.0, 50.0, &drresult);
		cout << " value is " << drresult << endl;
	}

	CoUninitialize();
	return 0;
}

exe is 64 bit dll is 32 bit
Posted
Updated 2-May-16 21:12pm
v2

How did you register your COM dll?
By default the 64-bit version of RegSvr32 is used and you need to use the 32-bit version.
See https://support.microsoft.com/en-us/kb/249873[^]

And here is some general information: Process Interoperability (Windows)[^]
 
Share this answer
 
Comments
Gayle123 3-May-16 1:37am    
i didnt get can u explain once please
George Jonsson 3-May-16 2:30am    
What is it you don't understand?
Gayle123 3-May-16 1:47am    
com dll can be registered anywhere..right ...
George Jonsson 3-May-16 2:29am    
Well, avoid the system directories.
Unless I misunderstood the documentation, you cannot do that. See Process Interoperability (Windows)[^]:
On 64-bit Windows, a 64-bit process cannot load a 32-bit dynamic-link library (DLL). Additionally, a 32-bit process cannot load a 64-bit DLL.
 
Share this answer
 
Comments
Gayle123 3-May-16 4:37am    
how to call 32 bit dll from 64 bit exe
CPallini 3-May-16 4:52am    
Simply stated, you cannot.
However, you might try the following workaround (I've not tested it myself):
http://www.gfi.com/blog/32bit-object-64bit-environment/
Gayle123 3-May-16 5:39am    
this failed in my case i tied this .. could you suggest different idea
Gayle123 3-May-16 5:40am    
can u try once please..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900