Click here to Skip to main content
15,880,608 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I need to call native library function
C++
(long (WINAPI*)(long, unsigned short *, long, int(__cdecl *)(long, long, eMcamStatus, void*), void*);

in c++ cli visual studio project i have this:

1-structure for native function
C++
ref struct Stuct_Test
{
 long    ResolutionIndex;
 long    BinningFactor;
 long    BitsPerPixel;
 String^ DisplayName;
};


2-delegate for call back
C++
delegate int Call_Back_Type(Int32, Int32, Stuct_Test, IntPtr);


3-call back proccessing function
C++
int Call_Back(Int32 Long1, Int32 Long2, Stuct_Test Struct1, IntPtr Void1)

4-pinvoke function

C++
[DllImport("mrfw.dll", EntryPoint = "_McammAcquisitionEx@20")]
static long Camm_Acquisition(Int32, StringBuilder^, Call_Back_Type^, IntPtr);


i am calling it like this
C++
Type_Test^ Test = gcnew Type_Test;

Type_Test::Call_Back_Type^ Call_Back_Function = gcnew Type_Test::Call_Back_Type(Test, &Type_Test::Call_Back);
StringBuilder^ Result_Image;
long Camera_Index = 1;
IntPtr Extra_Parameter;

long Result = Type_Test::Camm_Acquisition(Camera_Index, Result_Image, Call_Back_Function, Extra_Parameter);

and i have exception

Managed Debugging Assistant 'PInvokeStackImbalance' has detected a problem in 'D:\mapx\Mapx\Debug\Mapx.exe'. Additional Information: A call to PInvoke function 'Mapx!Type_Test::Camm_Acquisition' has unbalanced the stack. This is likely because the managed PInvoke signature does not match the unmanaged target signature. Check that the calling convention and parameters of the PInvoke signature match the target unmanaged signature.


What is wrong? How "pinvoke function" should looks like? Where i can found conversion table? May be exist a better way t do this?

Thank you
Posted
Updated 8-Dec-14 23:57pm
v2

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



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