C# Programming
10-09-2009, 03:30 AM
Hello,
I am Developing a C# WINDOWS application. In my Application i need to call a cpp dll which returns the list of Drives
connected to the PC.
The Function is "int GetDeviceDiskName(char**);". I can get all the drive names in my vc++ application after i call this
function.
char *device[10];
for(int i = 0; i < 10; i++)
{
device[i] = new char[10];
memset(device[i],0,10);
}
int nRes = GetDeviceDiskName(device);
device returns all the USB's attached to the PC.
But I have Trobule calling this function in C#.Net.
In my c# code i have declared the function in this manner,
[DllImport("../../Hanlin.dll", SetLastError = true, CharSet = CharSet.Ansi,CallingConvention = CallingConvention.Cdecl)]
public static extern Int32 GetDeviceDiskName(String[] deviceName);
In c# i tried to call this function in this way,
char[] deviceName = new char[10];
int nStatus = GetHanlinDeviceDiskName(ref deviceName);
But I get Error as "Additional information: Attempted to read or write protected memory. This is often an indication that
other memory is corrupt."
Can some one help me how to call this function.
In the Dll file the "device" array will be updated in this way,
if(bDiskFound)
{
device[cnt][0]=cDiskID;
cnt++;
}
modified on Thursday, October 8, 2009 9:09 AM
I am Developing a C# WINDOWS application. In my Application i need to call a cpp dll which returns the list of Drives
connected to the PC.
The Function is "int GetDeviceDiskName(char**);". I can get all the drive names in my vc++ application after i call this
function.
char *device[10];
for(int i = 0; i < 10; i++)
{
device[i] = new char[10];
memset(device[i],0,10);
}
int nRes = GetDeviceDiskName(device);
device returns all the USB's attached to the PC.
But I have Trobule calling this function in C#.Net.
In my c# code i have declared the function in this manner,
[DllImport("../../Hanlin.dll", SetLastError = true, CharSet = CharSet.Ansi,CallingConvention = CallingConvention.Cdecl)]
public static extern Int32 GetDeviceDiskName(String[] deviceName);
In c# i tried to call this function in this way,
char[] deviceName = new char[10];
int nStatus = GetHanlinDeviceDiskName(ref deviceName);
But I get Error as "Additional information: Attempted to read or write protected memory. This is often an indication that
other memory is corrupt."
Can some one help me how to call this function.
In the Dll file the "device" array will be updated in this way,
if(bDiskFound)
{
device[cnt][0]=cDiskID;
cnt++;
}
modified on Thursday, October 8, 2009 9:09 AM