NotSupportedException while calling native method

G

Guest

Hello Friends,
I made a 'dll' in C++ with Visual Studio 2005 with one
function. I defined the export function with Extern 'C' to avoid C++
managling. After that added 'dll' to my C# test program and called the method
then I am getting Exception 'NotSupportedException'. Just to let you know
that I am using .NET compact framework 1.0. Can anybody help me what's going
wrong ? Here is complete code.


C++ code :


DWORD GetScreenOrientation()
{
DEVMODE devmode = {0};
devmode.dmSize = sizeof(DEVMODE);
devmode.dmFields = DM_DISPLAYORIENTATION;
ChangeDisplaySettingsEx(NULL, &devmode, 0, CDS_TEST, NULL);
return devmode.dmDisplayOrientation;
}



#ifdef __cplusplus
extern "C" {
#endif //__cplusplus

__declspec(dllexport) DWORD GetScreenOrientation();


#ifdef __cplusplus
} // extern "C"
#endif //__cplusplus


C# import declaration:

[DllImport("screenrotation.dll", EntryPoint = "GetScreenOrientation",
SetLastError = true, CharSet = CharSet.Unicode)]
public static extern long GetScreenOrientation();

Thanks in advance.

Regards,
-Santosh
 
G

Guest

thanks. Now It's working.

Thanks,
-Santosh

A DWORD is an int, not a long.

-Chris


Santosh said:
Hello Friends,
I made a 'dll' in C++ with Visual Studio 2005 with one
function. I defined the export function with Extern 'C' to avoid C++
managling. After that added 'dll' to my C# test program and called the
method
then I am getting Exception 'NotSupportedException'. Just to let you know
that I am using .NET compact framework 1.0. Can anybody help me what's
going
wrong ? Here is complete code.


C++ code :


DWORD GetScreenOrientation()
{
DEVMODE devmode = {0};
devmode.dmSize = sizeof(DEVMODE);
devmode.dmFields = DM_DISPLAYORIENTATION;
ChangeDisplaySettingsEx(NULL, &devmode, 0, CDS_TEST, NULL);
return devmode.dmDisplayOrientation;
}



#ifdef __cplusplus
extern "C" {
#endif //__cplusplus

__declspec(dllexport) DWORD GetScreenOrientation();


#ifdef __cplusplus
} // extern "C"
#endif //__cplusplus


C# import declaration:

[DllImport("screenrotation.dll", EntryPoint = "GetScreenOrientation",
SetLastError = true, CharSet = CharSet.Unicode)]
public static extern long GetScreenOrientation();

Thanks in advance.

Regards,
-Santosh
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top