Reputation: 366
I need to call native function
long (WINAPI*)(long,long*);
In long* it will give me the result
i am doing this
[DllImport("mrfw.dll", EntryPoint = "_McammGetCurrentBinning@8")]
static long Get_Current_Binning(Int32, IntPtr);
but this call is not working
Int32 Camera_Index= 0;
Int32 Result;
IntPtr Result_Pointer = IntPtr(Result);
long Binning = Get_Current_Binning(Camera_Index, Result_Pointer);
I have the exception System.AccessViolationException So, function can not write me the result.
How to do this?
Thank you.
Update
Hey guys. I do not know what you all mean, but i did ask, what i did ask.
-I am using c++ cli. it is not c#
-I need pinvoke. I can not call unmanaget dll from cli project
-i did found the solution by doing this. You can delete my answers, give me the minuses, but it is working. It is so bad?
[DllImport("mrfw.dll", EntryPoint = "_McammGetCurrentBinning@8")]
static long Get_Current_Binning(Int32, IntPtr);
int main(array<System::String ^> ^args)
{
Int32 Camera_Index= 0;
Byte* Result= new Byte(4);
IntPtr Result_Pointer = IntPtr(Result);
long Binning = Get_Current_Binning(Camera_Index, Result_Pointer);
}
Upvotes: 0
Views: 305
Reputation: 612804
You are coding in mixed mode C++/CLI and there's no need for p/invoke. If what you have is a DLL without a .lib file, and a mixed mode C++/CLI program, then you have a couple of options.
LoadLibrary
and GetProcAddress
.In either case you will be able to call the function like this:
long result;
long retval = Get_Current_Binning(0, &result);
// check retval for success, and if so the result contains the returned value
Upvotes: 1