Click to See Complete Forum and Search --> : problem passing managed form's handle to unmanaged dll native code function


James_dean
February 2nd, 2007, 05:24 AM
I want to call the following function in a native code dll from my managed code:
bool myInstallFunc(HWND hWnd, LPTSTR param1, DWORD param2, LPTSTR param3);

I tried this in my code but i get all sorts of errors but i think the format is correct........

[DllImport("myInstaller", CharSet=CharSet::Ansi)]
extern "C" bool myInstallFunc([MarshalAs(UnmanagedType::HWND)]void* hWnd, [MarshalAs(UnmanagedType::LPTSTR)]String^ pText, [MarshalAs(UnmanagedType::DWORD)]unsigned long^ param, [MarshalAs(UnmanagedType::LPTSTR)]String^ uType);

James2007
February 4th, 2007, 04:42 PM
[DllImport("myInstallFunc",CharSet=CharSet::Ansi)] bool myInstallFunc(System::IntPtr hWnd, [MarshalAs(UnmanagedType::LPTSTR)]String^ pText, unsigned long param2, [MarshalAs(UnmanagedType::LPTSTR)]String^ uType);




And the MarshalAs attribute is probably not necessary, see CharSet::Ansi of the DllImport attribute. It should be done implicitally.