PInvoke: super stuck on this one :0(

S

sklett

Just when I thought working with this unmanaged DLL could get any more
difficult.... I have to deal with this:
<exception>
{"An attempt was made to load a program with an incorrect format. (Exception
from HRESULT: 0x8007000B)"}
<exception>

Here is the sig. of the unmanaged DLL I'm trying to call:
<unmanaged code>
int MSP430_FET_FwUpdate(LPTSTR lpszFileName, MSP430_FET_NOTIFY_FUNC
callback, LONG clientHandle);
</unmanaged code>

The signature of the callback:
<callback>
typedef void (* MSP430_FET_NOTIFY_FUNC) (UINT MsgId, WPARAM wParam,
LPARAM lParam, LONG clientHandle);
</callback>


I researched how to deal with a callback using delegates and I think I have
that part correct ( I will post in a little later) Here is the signature
for my managed function:
<code>
public delegate void TIFETUpdateCallback(uint MsgId, uint wParam, int
lParam, int clientHandle);

[DllImport(@"C:\adt430\MSP430_DLL\Inc\MSP430_FET.h")]
public static extern string MSP430_FET_FwUpdate( string lpszFileName,
TIFETUpdateCallback callback, int clientHandle);
</code>

I'm not sure what to pass to the last parameter. The comments in the
unmanaged h file say to pass a handle to the calling application, but I'm
calling this is a class library and am not sure what to pass to it.

And here is the code where I call the above function:
<code>
TIMSP430Driver.MSP430_FET_FwUpdate(string.Empty, new
TIFETUpdateCallback(UpdateCallback), 1);

public static void UpdateCallback(uint MsgId, uint wParam, int lParam,
int clientHandle)
{
// do something
int y = 4;
}
</code>



I'm in waaaaay over my head. Google isn't turning up anything for this
exception.

Does anyone see the problem here? Your help will be very much appreciated!

Thanks for reading,
Steve
 
M

Mattias Sjögren

{"An attempt was made to load a program with an incorrect format. (Exception
from HRESULT: 0x8007000B)"}
<exception> ....
[DllImport(@"C:\adt430\MSP430_DLL\Inc\MSP430_FET.h")]

The DllImport attribute should point to the executable DLL file
exporting the function, not the C++ header file where they are
declared.


Mattias
 
S

sklett

I'm sorry, that was a typo. It is indeed set to the dll filename.


Mattias Sjögren said:
<exception>
{"An attempt was made to load a program with an incorrect format.
(Exception
from HRESULT: 0x8007000B)"}
<exception> ...
[DllImport(@"C:\adt430\MSP430_DLL\Inc\MSP430_FET.h")]

The DllImport attribute should point to the executable DLL file
exporting the function, not the C++ header file where they are
declared.


Mattias
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top