Click here to Skip to main content
15,891,934 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Iam calling a method in C++ DLL form C# application:

Method in C++ DLL:
int ImageSize_(PUC i_puc_Header,UL i_ul_HeaderSize,PUL o_pul_UnHeaderSize)
{
//code here

*o_pul_UnHeaderSize=somevalue;/*i am assigning some calculated value to this unsigned long pointer in this line only am getting error. am confirming this by putting debug statements i tried using out modifier and UintPtr ref type.....*/
}
Here am declaring that method in C# as follows

public static extern int ImageSize(byte[] i_puc_Header, long i_ul_HeaderSize, ref UInt32 o_pul_UnHeaderSize);

Then am calling the method as follows.

ImageSize( Buffer1, Sizeofbuffer,ref image_size);

I searched in net to resolve it but i could not figure it out.Any help highly appreciated.
Thanks in advance
Posted
Comments
[no name] 17-Jul-14 12:48pm    
Please include the DllImport attribute in your declaration of ImageSize.
D Mahesh 18-Jul-14 0:15am    
//sorry bling, still same error for unsigned long pointer as Access violation exception
//I changed declaration like this
[DllImport("Image.dll", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true, SetLastError = false)]
public static extern int ImageSize([In] byte[] i_puc_Header, long i_ul_HeaderSize,[In] [Out] ref UInt32 o_pul_UnHeaderSize);
//and am calling like this
int retval1 = ImageSize( RawBuffer1, Sizeofbuffer,ref image_size);
//earler also my issue is with unsigned long pointer
Bernhard Hiller 18-Jul-14 2:56am    
Does the C++ function do anything with o_pul_UnHeaderSize before it sets it to somevalue? If not, "out" instead of "ref" could do the trick.
D Mahesh 18-Jul-14 3:31am    
ya tried following way as u said not worked same error
Declaration:
[DllImport("Image.dll", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true, SetLastError = false)]
public static extern int ImageSize([In] byte[] i_puc_Header, long i_ul_HeaderSize, [Out] out UInt32 o_pul_UnHeaderSize);
Calling:
int retval1 = ImageSize( Buffer1, Sizeofbuffer,out image_size);

I'll assume your DLL is named "image.dll". Any arrays need to be marked as [In] or [Out]. Try this ...

VB
[DllImport("image.dll", CallingConvention=CallingConvention.Cdecl,
             ExactSpelling=true, SetLastError=false)]
public static extern int ImageSize([In] byte[] i_puc_Header, long i_ul_HeaderSize, [Out] ref UInt32 o_pul_UnHeaderSize);
 
Share this answer
 
actual error was on 2 nd argument.
c++ long has 4 bytes so we should replace in our c# application with int(4 bytes)
 
Share this answer
 

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