Click here to Skip to main content
15,867,453 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
See more:
hello...everyone!
here i have a question, i need to call a method of dll based on c++, the method parameter type is "void*",in c# project, i input a quote of object,well, all is ok in the process of compiling, but there is a exception when run the program...
so i sincerely hope someone could help to solve the problem, thanks...
Posted
Comments
OriginalGriff 1-Mar-12 3:33am    
We would need to see the C++ method declaration, and some idea what it does with them.
A clue as to what the exception message was would help, too.
csuzj 5-Mar-12 3:34am    
Maybe the parameter type transformation problem,still thank you...
Lakamraju Raghuram 1-Mar-12 3:53am    
It would be helpful if you provide code snippets of your c++ signature and how you are calling it in C#
csuzj 5-Mar-12 3:38am    
SuperDStereoLib.SDOnCreate(SuperDStereoLib.E_DPFormat_Type.EDT_8V, SuperDStereoLib.E_DRIVER_TYPE.EDT_D3D8V, device);
the third parameter is a reference of a object,which is a instance of Microsoft.DircexX.device
OriginalGriff 1-Mar-12 4:01am    
Univote countered

Look at "interop" in the .NET documentation (attribute
Calling a C++ function is just like calling the Windows API.
For instance:


C#
[DllImport("kernel32.dll", EntryPoint = "LoadLibraryW", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Winapi)]
private static extern IntPtr LoadLibrary(string fileName);

[DllImport("kernel32.dll", EntryPoint = "FreeLibrary", CallingConvention = CallingConvention.Winapi)]
private static extern IntPtr FreeLibrary(IntPtr hModule);

// There is no Unicode version of GetProcAddress.
[DllImport("kernel32.dll", CharSet=CharSet.Ansi, ExactSpelling=true, SetLastError=true, CallingConvention=CallingConvention.Winapi)]
internal static extern IntPtr GetProcAddress(IntPtr hModule, string procName );

[DllImport("ole32.dll", CallingConvention=CallingConvention.StdCall)]
static extern void CoFreeUnusedLibrariesEx(int msUnloadDelay, int MustBeZero);


I think void * can be translated to IntPtr.
Hope this helps,
Pablo.
 
Share this answer
 
at first include:

C#
using System.Runtime.InteropServices;
using System.Text;


then:

C#
[DllImport("kernel32")]
        private static extern long WritePrivateProfileInt(String Section, String Key, int Value, String FilePath);


let me explain:

[DllImport( "your_dll_name")]
private static extern your_function_type(like_int,char,IntPtr..) your_function_name(function_param1,...);

void* = IntPtr
 
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