problem with P/Involke

W

Wrecked

Hello,

I was trying to use the CeCreateFile function of rapi.dll in my c#
code.. All i am trying to do in the program bellow is to create a
file..
but when i try to run the program i get a MissingMethodException -
"Can't find PInvoke DLL 'rapi.dll'."

Is there something wrong with code -- and do we need to place rapi.dll
at some specific location(currently i have placed in the same folder
where i am deploying my project).
I am not very familiar with P/Invoke.. you help will be greatly
appreciated.

Thanks
Rithesh



static void Main()

{

MessageBox.Show("Before Invoking");

short FILE_ATTRIBUTE_NORMAL = 0x80;
short FILE_ATTRIBUTE_DIRECTORY = 0x10;
short FILE_ATTRIBUTE_TEMPORARY = 0x100;
uint GENERIC_READ = 0x80000000;
uint GENERIC_WRITE = 0x40000000;
short CREATE_NEW = 1;
short CREATE_ALWAYS = 2;
short OPEN_EXISTING = 3;

int handle = CeCreateFile("xxxx", GENERIC_WRITE, 0, 0,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);

MessageBox.Show("Card handle is - " + handle);

// End of card related code //

}


[StructLayout(LayoutKind.Sequential)]
public struct OSVERSIONINFO
{
public int dwOSVersionInfoSize;
public int dwMajorVersion;
public int dwMinorVersion;
public int dwBuildNumber;
public int dwPlatformId;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
public string szCSDVersion;
}

[StructLayout(LayoutKind.Sequential)]
public struct RAPIINIT
{
int cbSize;
int heRapiInit;
int hrRapiInit;
}

[StructLayout(LayoutKind.Sequential)]
public struct SECURITY_ATTRIBUTES
{
public int nLength;
public int lpSecurityDescriptor;
public int bInheritHandle;
}

[DllImport("rapi.dll", CharSet = CharSet.Unicode)]
public static extern int CeCloseHandle(int hObject);

[DllImport("rapi.dll", CharSet = CharSet.Unicode)]
public static extern int CeCreateFile(string lpFileName, uint
dwDesiredAccess, int dwShareMode, int lpSecurityAttributes, int
dwCreationDisposition, int dwFlagsAndAttributes, int
hTemplateFile);

[DllImport("rapi.dll", CharSet = CharSet.Unicode)]
public static extern int
CeRapiInitEx([MarshalAs(UnmanagedType.Struct)] ref RAPIINIT pRapiInit);

[DllImport("rapi.dll", CharSet = CharSet.Unicode)]
public static extern int CeRapiInit();

[DllImport("rapi.dll", CharSet = CharSet.Unicode)]
public static extern int CeRapiUninit();

[DllImport("rapi.dll", CharSet = CharSet.Unicode)]
public static extern int CeReadFile(int hFile, StringBuilder
lpBuffer, int nNumberOfbytesToRead, out int lpNumberOfbytesRead, int
lpOverlapped);

[DllImport("rapi.dll", CharSet = CharSet.Unicode)]
public static extern int CeWriteFile(int hFile, StringBuilder
lpBuffer, int nNumberOfbytesToWrite, out int lpNumberOfbytesWritten,
int lpOverlapped);

[DllImport("rapi.dll", CharSet = CharSet.Unicode)]
public static extern int GetLastError();

[DllImport("rapi.dll", CharSet = CharSet.Unicode)]
public static extern int CeSetEndOfFile(int hFile);

[DllImport("rapi.dll", CharSet = CharSet.Unicode)]
public static extern int CeGetFileSize(int hFile, int
lpFileSizeHigh);

[DllImport("rapi.dll", CharSet = CharSet.Unicode)]
public static extern int CeGetLastError();

}
 
G

Guest

Is ActiveSync installed on the PC (this is code running on the PC, right?)


--
Chris Tacke
OpenNETCF Consulting
Managed Code in the Embedded World
www.opennetcf.com
--


Wrecked said:
Hello,

I was trying to use the CeCreateFile function of rapi.dll in my c#
code.. All i am trying to do in the program bellow is to create a
file..
but when i try to run the program i get a MissingMethodException -
"Can't find PInvoke DLL 'rapi.dll'."

Is there something wrong with code -- and do we need to place rapi.dll
at some specific location(currently i have placed in the same folder
where i am deploying my project).
I am not very familiar with P/Invoke.. you help will be greatly
appreciated.

Thanks
Rithesh



static void Main()

{

MessageBox.Show("Before Invoking");

short FILE_ATTRIBUTE_NORMAL = 0x80;
short FILE_ATTRIBUTE_DIRECTORY = 0x10;
short FILE_ATTRIBUTE_TEMPORARY = 0x100;
uint GENERIC_READ = 0x80000000;
uint GENERIC_WRITE = 0x40000000;
short CREATE_NEW = 1;
short CREATE_ALWAYS = 2;
short OPEN_EXISTING = 3;

int handle = CeCreateFile("xxxx", GENERIC_WRITE, 0, 0,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);

MessageBox.Show("Card handle is - " + handle);

// End of card related code //

}


[StructLayout(LayoutKind.Sequential)]
public struct OSVERSIONINFO
{
public int dwOSVersionInfoSize;
public int dwMajorVersion;
public int dwMinorVersion;
public int dwBuildNumber;
public int dwPlatformId;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
public string szCSDVersion;
}

[StructLayout(LayoutKind.Sequential)]
public struct RAPIINIT
{
int cbSize;
int heRapiInit;
int hrRapiInit;
}

[StructLayout(LayoutKind.Sequential)]
public struct SECURITY_ATTRIBUTES
{
public int nLength;
public int lpSecurityDescriptor;
public int bInheritHandle;
}

[DllImport("rapi.dll", CharSet = CharSet.Unicode)]
public static extern int CeCloseHandle(int hObject);

[DllImport("rapi.dll", CharSet = CharSet.Unicode)]
public static extern int CeCreateFile(string lpFileName, uint
dwDesiredAccess, int dwShareMode, int lpSecurityAttributes, int
dwCreationDisposition, int dwFlagsAndAttributes, int
hTemplateFile);

[DllImport("rapi.dll", CharSet = CharSet.Unicode)]
public static extern int
CeRapiInitEx([MarshalAs(UnmanagedType.Struct)] ref RAPIINIT pRapiInit);

[DllImport("rapi.dll", CharSet = CharSet.Unicode)]
public static extern int CeRapiInit();

[DllImport("rapi.dll", CharSet = CharSet.Unicode)]
public static extern int CeRapiUninit();

[DllImport("rapi.dll", CharSet = CharSet.Unicode)]
public static extern int CeReadFile(int hFile, StringBuilder
lpBuffer, int nNumberOfbytesToRead, out int lpNumberOfbytesRead, int
lpOverlapped);

[DllImport("rapi.dll", CharSet = CharSet.Unicode)]
public static extern int CeWriteFile(int hFile, StringBuilder
lpBuffer, int nNumberOfbytesToWrite, out int lpNumberOfbytesWritten,
int lpOverlapped);

[DllImport("rapi.dll", CharSet = CharSet.Unicode)]
public static extern int GetLastError();

[DllImport("rapi.dll", CharSet = CharSet.Unicode)]
public static extern int CeSetEndOfFile(int hFile);

[DllImport("rapi.dll", CharSet = CharSet.Unicode)]
public static extern int CeGetFileSize(int hFile, int
lpFileSizeHigh);

[DllImport("rapi.dll", CharSet = CharSet.Unicode)]
public static extern int CeGetLastError();

}
 
W

Wrecked

No this code is not running on the pc, i am using an imate device to
test this.. i have activesync installed though

Is ActiveSync installed on the PC (this is code running on the PC, right?)

--
Chris Tacke
OpenNETCF Consulting
Managed Code in the Embedded Worldwww.opennetcf.com
--

Wrecked said:
I was trying to use the CeCreateFile function of rapi.dll in my c#
code.. All i am trying to do in the program bellow is to create a
file..
but when i try to run the program i get a MissingMethodException -
"Can't find PInvoke DLL 'rapi.dll'."
Is there something wrong with code -- and do we need to place rapi.dll
at some specific location(currently i have placed in the same folder
where i am deploying my project).
I am not very familiar with P/Invoke.. you help will be greatly
appreciated.

static void Main()

MessageBox.Show("Before Invoking");
short FILE_ATTRIBUTE_NORMAL = 0x80;
short FILE_ATTRIBUTE_DIRECTORY = 0x10;
short FILE_ATTRIBUTE_TEMPORARY = 0x100;
uint GENERIC_READ = 0x80000000;
uint GENERIC_WRITE = 0x40000000;
short CREATE_NEW = 1;
short CREATE_ALWAYS = 2;
short OPEN_EXISTING = 3;
int handle = CeCreateFile("xxxx", GENERIC_WRITE, 0, 0,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
MessageBox.Show("Card handle is - " + handle);
// End of card related code //

[StructLayout(LayoutKind.Sequential)]
public struct OSVERSIONINFO
{
public int dwOSVersionInfoSize;
public int dwMajorVersion;
public int dwMinorVersion;
public int dwBuildNumber;
public int dwPlatformId;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
public string szCSDVersion;
}
[StructLayout(LayoutKind.Sequential)]
public struct RAPIINIT
{
int cbSize;
int heRapiInit;
int hrRapiInit;
}
[StructLayout(LayoutKind.Sequential)]
public struct SECURITY_ATTRIBUTES
{
public int nLength;
public int lpSecurityDescriptor;
public int bInheritHandle;
}
[DllImport("rapi.dll", CharSet = CharSet.Unicode)]
public static extern int CeCloseHandle(int hObject);
[DllImport("rapi.dll", CharSet = CharSet.Unicode)]
public static extern int CeCreateFile(string lpFileName, uint
dwDesiredAccess, int dwShareMode, int lpSecurityAttributes, int
dwCreationDisposition, int dwFlagsAndAttributes, int
hTemplateFile);
[DllImport("rapi.dll", CharSet = CharSet.Unicode)]
public static extern int
CeRapiInitEx([MarshalAs(UnmanagedType.Struct)] ref RAPIINIT pRapiInit);
[DllImport("rapi.dll", CharSet = CharSet.Unicode)]
public static extern int CeRapiInit();
[DllImport("rapi.dll", CharSet = CharSet.Unicode)]
public static extern int CeRapiUninit();
[DllImport("rapi.dll", CharSet = CharSet.Unicode)]
public static extern int CeReadFile(int hFile, StringBuilder
lpBuffer, int nNumberOfbytesToRead, out int lpNumberOfbytesRead, int
lpOverlapped);
[DllImport("rapi.dll", CharSet = CharSet.Unicode)]
public static extern int CeWriteFile(int hFile, StringBuilder
lpBuffer, int nNumberOfbytesToWrite, out int lpNumberOfbytesWritten,
int lpOverlapped);
[DllImport("rapi.dll", CharSet = CharSet.Unicode)]
public static extern int GetLastError();
[DllImport("rapi.dll", CharSet = CharSet.Unicode)]
public static extern int CeSetEndOfFile(int hFile);
[DllImport("rapi.dll", CharSet = CharSet.Unicode)]
public static extern int CeGetFileSize(int hFile, int
lpFileSizeHigh);
[DllImport("rapi.dll", CharSet = CharSet.Unicode)]
public static extern int CeGetLastError();
 
G

Guest

Well that's the problem. RAPI is a desktop set of APIs. If you want to
create or open a file, call CreateFile.And with managed code, use one of the
classes in System.IO, which is what
they're for.


--
Chris Tacke
OpenNETCF Consulting
Managed Code in the Embedded World
www.opennetcf.com
--


Wrecked said:
No this code is not running on the pc, i am using an imate device to
test this.. i have activesync installed though

Is ActiveSync installed on the PC (this is code running on the PC,
right?)

--
Chris Tacke
OpenNETCF Consulting
Managed Code in the Embedded Worldwww.opennetcf.com
--

I was trying to use the CeCreateFile function of rapi.dll in my c#
code.. All i am trying to do in the program bellow is to create a
file..
but when i try to run the program i get a MissingMethodException -
"Can't find PInvoke DLL 'rapi.dll'."
Is there something wrong with code -- and do we need to place rapi.dll
at some specific location(currently i have placed in the same folder
where i am deploying my project).
I am not very familiar with P/Invoke.. you help will be greatly
appreciated.

static void Main()

MessageBox.Show("Before Invoking");
short FILE_ATTRIBUTE_NORMAL = 0x80;
short FILE_ATTRIBUTE_DIRECTORY = 0x10;
short FILE_ATTRIBUTE_TEMPORARY = 0x100;
uint GENERIC_READ = 0x80000000;
uint GENERIC_WRITE = 0x40000000;
short CREATE_NEW = 1;
short CREATE_ALWAYS = 2;
short OPEN_EXISTING = 3;
int handle = CeCreateFile("xxxx", GENERIC_WRITE, 0, 0,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
MessageBox.Show("Card handle is - " + handle);
// End of card related code //

[StructLayout(LayoutKind.Sequential)]
public struct OSVERSIONINFO
{
public int dwOSVersionInfoSize;
public int dwMajorVersion;
public int dwMinorVersion;
public int dwBuildNumber;
public int dwPlatformId;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
public string szCSDVersion;
}
[StructLayout(LayoutKind.Sequential)]
public struct RAPIINIT
{
int cbSize;
int heRapiInit;
int hrRapiInit;
}
[StructLayout(LayoutKind.Sequential)]
public struct SECURITY_ATTRIBUTES
{
public int nLength;
public int lpSecurityDescriptor;
public int bInheritHandle;
}
[DllImport("rapi.dll", CharSet = CharSet.Unicode)]
public static extern int CeCloseHandle(int hObject);
[DllImport("rapi.dll", CharSet = CharSet.Unicode)]
public static extern int CeCreateFile(string lpFileName, uint
dwDesiredAccess, int dwShareMode, int lpSecurityAttributes, int
dwCreationDisposition, int dwFlagsAndAttributes, int
hTemplateFile);
[DllImport("rapi.dll", CharSet = CharSet.Unicode)]
public static extern int
CeRapiInitEx([MarshalAs(UnmanagedType.Struct)] ref RAPIINIT pRapiInit);
[DllImport("rapi.dll", CharSet = CharSet.Unicode)]
public static extern int CeRapiInit();
[DllImport("rapi.dll", CharSet = CharSet.Unicode)]
public static extern int CeRapiUninit();
[DllImport("rapi.dll", CharSet = CharSet.Unicode)]
public static extern int CeReadFile(int hFile, StringBuilder
lpBuffer, int nNumberOfbytesToRead, out int lpNumberOfbytesRead, int
lpOverlapped);
[DllImport("rapi.dll", CharSet = CharSet.Unicode)]
public static extern int CeWriteFile(int hFile, StringBuilder
lpBuffer, int nNumberOfbytesToWrite, out int lpNumberOfbytesWritten,
int lpOverlapped);
[DllImport("rapi.dll", CharSet = CharSet.Unicode)]
public static extern int GetLastError();
[DllImport("rapi.dll", CharSet = CharSet.Unicode)]
public static extern int CeSetEndOfFile(int hFile);
[DllImport("rapi.dll", CharSet = CharSet.Unicode)]
public static extern int CeGetFileSize(int hFile, int
lpFileSizeHigh);
[DllImport("rapi.dll", CharSet = CharSet.Unicode)]
public static extern int CeGetLastError();
 
W

Wrecked

Hi Chris,
I am not sure if the below code is what u suggested to do..
however i am still getting the same error.. that is "Can't find PInvoke
DLL 'kernel32.dll'.".. i am doing something fundamentally wrong???







static void Main(string[] args)
{


IntPtr ptr = CreateFile("DSK1",
FileAccess.ReadWrite,
FileShare.ReadWrite,
0,
FileMode.Create,
0,
IntPtr.Zero); //pointed out by Parrys

MessageBox.Show("the handle is - " + ptr.ToString());
}


[DllImport("Kernel32.dll")]
static extern IntPtr CreateFile(
string filename,
[MarshalAs(UnmanagedType.U4)]FileAccess
fileaccess,
[MarshalAs(UnmanagedType.U4)]FileShare
fileshare,
int securityattributes,
[MarshalAs(UnmanagedType.U4)]FileMode
creationdisposition,
int flags,
IntPtr template);
}




Well that's the problem. RAPI is a desktop set of APIs. If you want to
create or open a file, call CreateFile.And with managed code, use one of the
classes in System.IO, which is what
they're for.

--
Chris Tacke
OpenNETCF Consulting
Managed Code in the Embedded Worldwww.opennetcf.com
--

Wrecked said:
No this code is not running on the pc, i am using an imate device to
test this.. i have activesync installed though
Is ActiveSync installed on the PC (this is code running on the PC,
right?)
--
Chris Tacke
OpenNETCF Consulting
Managed Code in the Embedded Worldwww.opennetcf.com
--
message
Hello,
I was trying to use the CeCreateFile function of rapi.dll in my c#
code.. All i am trying to do in the program bellow is to create a
file..
but when i try to run the program i get a MissingMethodException -
"Can't find PInvoke DLL 'rapi.dll'."
Is there something wrong with code -- and do we need to place rapi.dll
at some specific location(currently i have placed in the same folder
where i am deploying my project).
I am not very familiar with P/Invoke.. you help will be greatly
appreciated.
Thanks
Rithesh
static void Main()
{
MessageBox.Show("Before Invoking");
short FILE_ATTRIBUTE_NORMAL = 0x80;
short FILE_ATTRIBUTE_DIRECTORY = 0x10;
short FILE_ATTRIBUTE_TEMPORARY = 0x100;
uint GENERIC_READ = 0x80000000;
uint GENERIC_WRITE = 0x40000000;
short CREATE_NEW = 1;
short CREATE_ALWAYS = 2;
short OPEN_EXISTING = 3;
int handle = CeCreateFile("xxxx", GENERIC_WRITE, 0, 0,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
MessageBox.Show("Card handle is - " + handle);
// End of card related code //
}
[StructLayout(LayoutKind.Sequential)]
public struct OSVERSIONINFO
{
public int dwOSVersionInfoSize;
public int dwMajorVersion;
public int dwMinorVersion;
public int dwBuildNumber;
public int dwPlatformId;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
public string szCSDVersion;
}
[StructLayout(LayoutKind.Sequential)]
public struct RAPIINIT
{
int cbSize;
int heRapiInit;
int hrRapiInit;
}
[StructLayout(LayoutKind.Sequential)]
public struct SECURITY_ATTRIBUTES
{
public int nLength;
public int lpSecurityDescriptor;
public int bInheritHandle;
}
[DllImport("rapi.dll", CharSet = CharSet.Unicode)]
public static extern int CeCloseHandle(int hObject);
[DllImport("rapi.dll", CharSet = CharSet.Unicode)]
public static extern int CeCreateFile(string lpFileName, uint
dwDesiredAccess, int dwShareMode, int lpSecurityAttributes, int
dwCreationDisposition, int dwFlagsAndAttributes, int
hTemplateFile);
[DllImport("rapi.dll", CharSet = CharSet.Unicode)]
public static extern int
CeRapiInitEx([MarshalAs(UnmanagedType.Struct)] ref RAPIINIT pRapiInit);
[DllImport("rapi.dll", CharSet = CharSet.Unicode)]
public static extern int CeRapiInit();
[DllImport("rapi.dll", CharSet = CharSet.Unicode)]
public static extern int CeRapiUninit();
[DllImport("rapi.dll", CharSet = CharSet.Unicode)]
public static extern int CeReadFile(int hFile, StringBuilder
lpBuffer, int nNumberOfbytesToRead, out int lpNumberOfbytesRead, int
lpOverlapped);
[DllImport("rapi.dll", CharSet = CharSet.Unicode)]
public static extern int CeWriteFile(int hFile, StringBuilder
lpBuffer, int nNumberOfbytesToWrite, out int lpNumberOfbytesWritten,
int lpOverlapped);
[DllImport("rapi.dll", CharSet = CharSet.Unicode)]
public static extern int GetLastError();
[DllImport("rapi.dll", CharSet = CharSet.Unicode)]
public static extern int CeSetEndOfFile(int hFile);
[DllImport("rapi.dll", CharSet = CharSet.Unicode)]
public static extern int CeGetFileSize(int hFile, int
lpFileSizeHigh);
[DllImport("rapi.dll", CharSet = CharSet.Unicode)]
public static extern int CeGetLastError();
}
 
G

Guest

Yes, you are doing something fundamentally wrong. kernel32.dll doesn't
exist in CE. CreateFile, like almost all Win32 functions in CE, is in
coredll.dll. I'd also double check all of those enum constants to make sure
they match what CreateFile is expecting. Also, I'm certain that DSK1 will
exist, so you should be using OPEN_EXISTING, probably not Create.


--
Chris Tacke
OpenNETCF Consulting
Managed Code in the Embedded World
www.opennetcf.com
--





Wrecked said:
Hi Chris,
I am not sure if the below code is what u suggested to do..
however i am still getting the same error.. that is "Can't find PInvoke
DLL 'kernel32.dll'.".. i am doing something fundamentally wrong???







static void Main(string[] args)
{


IntPtr ptr = CreateFile("DSK1",
FileAccess.ReadWrite,
FileShare.ReadWrite,
0,
FileMode.Create,
0,
IntPtr.Zero); //pointed out by Parrys

MessageBox.Show("the handle is - " + ptr.ToString());
}


[DllImport("Kernel32.dll")]
static extern IntPtr CreateFile(
string filename,
[MarshalAs(UnmanagedType.U4)]FileAccess
fileaccess,
[MarshalAs(UnmanagedType.U4)]FileShare
fileshare,
int securityattributes,
[MarshalAs(UnmanagedType.U4)]FileMode
creationdisposition,
int flags,
IntPtr template);
}




Well that's the problem. RAPI is a desktop set of APIs. If you want to
create or open a file, call CreateFile.And with managed code, use one of
the
classes in System.IO, which is what
they're for.

--
Chris Tacke
OpenNETCF Consulting
Managed Code in the Embedded Worldwww.opennetcf.com
--

No this code is not running on the pc, i am using an imate device to
test this.. i have activesync installed though
Is ActiveSync installed on the PC (this is code running on the PC,
right?)
--
Chris Tacke
OpenNETCF Consulting
Managed Code in the Embedded Worldwww.opennetcf.com
--
messagenews:[email protected]...

I was trying to use the CeCreateFile function of rapi.dll in my c#
code.. All i am trying to do in the program bellow is to create a
file..
but when i try to run the program i get a MissingMethodException -
"Can't find PInvoke DLL 'rapi.dll'."
Is there something wrong with code -- and do we need to place
rapi.dll
at some specific location(currently i have placed in the same folder
where i am deploying my project).
I am not very familiar with P/Invoke.. you help will be greatly
appreciated.

static void Main()

MessageBox.Show("Before Invoking");
short FILE_ATTRIBUTE_NORMAL = 0x80;
short FILE_ATTRIBUTE_DIRECTORY = 0x10;
short FILE_ATTRIBUTE_TEMPORARY = 0x100;
uint GENERIC_READ = 0x80000000;
uint GENERIC_WRITE = 0x40000000;
short CREATE_NEW = 1;
short CREATE_ALWAYS = 2;
short OPEN_EXISTING = 3;
int handle = CeCreateFile("xxxx", GENERIC_WRITE, 0, 0,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
MessageBox.Show("Card handle is - " + handle);
// End of card related code //

[StructLayout(LayoutKind.Sequential)]
public struct OSVERSIONINFO
{
public int dwOSVersionInfoSize;
public int dwMajorVersion;
public int dwMinorVersion;
public int dwBuildNumber;
public int dwPlatformId;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
public string szCSDVersion;
}
[StructLayout(LayoutKind.Sequential)]
public struct RAPIINIT
{
int cbSize;
int heRapiInit;
int hrRapiInit;
}
[StructLayout(LayoutKind.Sequential)]
public struct SECURITY_ATTRIBUTES
{
public int nLength;
public int lpSecurityDescriptor;
public int bInheritHandle;
}
[DllImport("rapi.dll", CharSet = CharSet.Unicode)]
public static extern int CeCloseHandle(int hObject);
[DllImport("rapi.dll", CharSet = CharSet.Unicode)]
public static extern int CeCreateFile(string lpFileName, uint
dwDesiredAccess, int dwShareMode, int lpSecurityAttributes, int
dwCreationDisposition, int dwFlagsAndAttributes, int
hTemplateFile);
[DllImport("rapi.dll", CharSet = CharSet.Unicode)]
public static extern int
CeRapiInitEx([MarshalAs(UnmanagedType.Struct)] ref RAPIINIT
pRapiInit);
[DllImport("rapi.dll", CharSet = CharSet.Unicode)]
public static extern int CeRapiInit();
[DllImport("rapi.dll", CharSet = CharSet.Unicode)]
public static extern int CeRapiUninit();
[DllImport("rapi.dll", CharSet = CharSet.Unicode)]
public static extern int CeReadFile(int hFile, StringBuilder
lpBuffer, int nNumberOfbytesToRead, out int lpNumberOfbytesRead, int
lpOverlapped);
[DllImport("rapi.dll", CharSet = CharSet.Unicode)]
public static extern int CeWriteFile(int hFile, StringBuilder
lpBuffer, int nNumberOfbytesToWrite, out int lpNumberOfbytesWritten,
int lpOverlapped);
[DllImport("rapi.dll", CharSet = CharSet.Unicode)]
public static extern int GetLastError();
[DllImport("rapi.dll", CharSet = CharSet.Unicode)]
public static extern int CeSetEndOfFile(int hFile);
[DllImport("rapi.dll", CharSet = CharSet.Unicode)]
public static extern int CeGetFileSize(int hFile, int
lpFileSizeHigh);
[DllImport("rapi.dll", CharSet = CharSet.Unicode)]
public static extern int CeGetLastError();
 
W

Wrecked

Chris,
That worked perfectly.. i did change that to open_existing(it was my
fault) .. it returned an handle(which is not 1- so assume that should
be write) thanks a lot.. i just wanted to know if there are also
implementations for deviceiocontrol and CloseHandle in coredll.dll. I
did write a small code to use deviceiocontrol from coredll -- however
it always returned false. I am not very sure how to use SG_REQ
structure in c#.. any help in that direction would be great ..
let me know if u want me paste that code..

Yes, you are doing something fundamentally wrong. kernel32.dll doesn't
exist in CE. CreateFile, like almost all Win32 functions in CE, is in
coredll.dll. I'd also double check all of those enum constants to make sure
they match what CreateFile is expecting. Also, I'm certain that DSK1 will
exist, so you should be using OPEN_EXISTING, probably not Create.

--
Chris Tacke
OpenNETCF Consulting
Managed Code in the Embedded Worldwww.opennetcf.com
--

Wrecked said:
Hi Chris,
I am not sure if the below code is what u suggested to do..
however i am still getting the same error.. that is "Can't find PInvoke
DLL 'kernel32.dll'.".. i am doing something fundamentally wrong???
static void Main(string[] args)
{
IntPtr ptr = CreateFile("DSK1",
FileAccess.ReadWrite,
FileShare.ReadWrite,
0,
FileMode.Create,
0,
IntPtr.Zero); //pointed out by Parrys
MessageBox.Show("the handle is - " + ptr.ToString());
}
[DllImport("Kernel32.dll")]
static extern IntPtr CreateFile(
string filename,
[MarshalAs(UnmanagedType.U4)]FileAccess
fileaccess,
[MarshalAs(UnmanagedType.U4)]FileShare
fileshare,
int securityattributes,
[MarshalAs(UnmanagedType.U4)]FileMode
creationdisposition,
int flags,
IntPtr template);
}
Well that's the problem. RAPI is a desktop set of APIs. If you want to
create or open a file, call CreateFile.And with managed code, use one of
the
classes in System.IO, which is what
they're for.
--
Chris Tacke
OpenNETCF Consulting
Managed Code in the Embedded Worldwww.opennetcf.com
--
message
No this code is not running on the pc, i am using an imate device to
test this.. i have activesync installed though
Is ActiveSync installed on the PC (this is code running on the PC,
right?)
--
Chris Tacke
OpenNETCF Consulting
Managed Code in the Embedded Worldwww.opennetcf.com
--
message
Hello,
I was trying to use the CeCreateFile function of rapi.dll in my c#
code.. All i am trying to do in the program bellow is to create a
file..
but when i try to run the program i get a MissingMethodException -
"Can't find PInvoke DLL 'rapi.dll'."
Is there something wrong with code -- and do we need to place
rapi.dll
at some specific location(currently i have placed in the same folder
where i am deploying my project).
I am not very familiar with P/Invoke.. you help will be greatly
appreciated.
Thanks
Rithesh
static void Main()
{
MessageBox.Show("Before Invoking");
short FILE_ATTRIBUTE_NORMAL = 0x80;
short FILE_ATTRIBUTE_DIRECTORY = 0x10;
short FILE_ATTRIBUTE_TEMPORARY = 0x100;
uint GENERIC_READ = 0x80000000;
uint GENERIC_WRITE = 0x40000000;
short CREATE_NEW = 1;
short CREATE_ALWAYS = 2;
short OPEN_EXISTING = 3;
int handle = CeCreateFile("xxxx", GENERIC_WRITE, 0, 0,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
MessageBox.Show("Card handle is - " + handle);
// End of card related code //
}
[StructLayout(LayoutKind.Sequential)]
public struct OSVERSIONINFO
{
public int dwOSVersionInfoSize;
public int dwMajorVersion;
public int dwMinorVersion;
public int dwBuildNumber;
public int dwPlatformId;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
public string szCSDVersion;
}
[StructLayout(LayoutKind.Sequential)]
public struct RAPIINIT
{
int cbSize;
int heRapiInit;
int hrRapiInit;
}
[StructLayout(LayoutKind.Sequential)]
public struct SECURITY_ATTRIBUTES
{
public int nLength;
public int lpSecurityDescriptor;
public int bInheritHandle;
}
[DllImport("rapi.dll", CharSet = CharSet.Unicode)]
public static extern int CeCloseHandle(int hObject);
[DllImport("rapi.dll", CharSet = CharSet.Unicode)]
public static extern int CeCreateFile(string lpFileName, uint
dwDesiredAccess, int dwShareMode, int lpSecurityAttributes, int
dwCreationDisposition, int dwFlagsAndAttributes, int
hTemplateFile);
[DllImport("rapi.dll", CharSet = CharSet.Unicode)]
public static extern int
CeRapiInitEx([MarshalAs(UnmanagedType.Struct)] ref RAPIINIT
pRapiInit);
[DllImport("rapi.dll", CharSet = CharSet.Unicode)]
public static extern int CeRapiInit();
[DllImport("rapi.dll", CharSet = CharSet.Unicode)]
public static extern int CeRapiUninit();
[DllImport("rapi.dll", CharSet = CharSet.Unicode)]
public static extern int CeReadFile(int hFile, StringBuilder
lpBuffer, int nNumberOfbytesToRead, out int lpNumberOfbytesRead, int
lpOverlapped);
[DllImport("rapi.dll", CharSet = CharSet.Unicode)]
public static extern int CeWriteFile(int hFile, StringBuilder
lpBuffer, int nNumberOfbytesToWrite, out int lpNumberOfbytesWritten,
int lpOverlapped);
[DllImport("rapi.dll", CharSet = CharSet.Unicode)]
public static extern int GetLastError();
[DllImport("rapi.dll", CharSet = CharSet.Unicode)]
public static extern int CeSetEndOfFile(int hFile);
[DllImport("rapi.dll", CharSet = CharSet.Unicode)]
public static extern int CeGetFileSize(int hFile, int
lpFileSizeHigh);
[DllImport("rapi.dll", CharSet = CharSet.Unicode)]
public static extern int CeGetLastError();
}
 
G

Guest

Yes, it's there. All of this is already done and tested in the
StreamInterfaceDriver class of the OpenNETCF SDF.

www.opennetcf.org/sdf


--
Chris Tacke
OpenNETCF Consulting
Managed Code in the Embedded World
www.opennetcf.com
--



Wrecked said:
Chris,
That worked perfectly.. i did change that to open_existing(it was my
fault) .. it returned an handle(which is not 1- so assume that should
be write) thanks a lot.. i just wanted to know if there are also
implementations for deviceiocontrol and CloseHandle in coredll.dll. I
did write a small code to use deviceiocontrol from coredll -- however
it always returned false. I am not very sure how to use SG_REQ
structure in c#.. any help in that direction would be great ..
let me know if u want me paste that code..

Yes, you are doing something fundamentally wrong. kernel32.dll doesn't
exist in CE. CreateFile, like almost all Win32 functions in CE, is in
coredll.dll. I'd also double check all of those enum constants to make
sure
they match what CreateFile is expecting. Also, I'm certain that DSK1
will
exist, so you should be using OPEN_EXISTING, probably not Create.

--
Chris Tacke
OpenNETCF Consulting
Managed Code in the Embedded Worldwww.opennetcf.com
--

Hi Chris,
I am not sure if the below code is what u suggested to do..
however i am still getting the same error.. that is "Can't find PInvoke
DLL 'kernel32.dll'.".. i am doing something fundamentally wrong???
static void Main(string[] args)
{
IntPtr ptr = CreateFile("DSK1",
FileAccess.ReadWrite,
FileShare.ReadWrite,
0,
FileMode.Create,
0,
IntPtr.Zero); //pointed out by Parrys
MessageBox.Show("the handle is - " + ptr.ToString());
}
[DllImport("Kernel32.dll")]
static extern IntPtr CreateFile(
string filename,
[MarshalAs(UnmanagedType.U4)]FileAccess
fileaccess,
[MarshalAs(UnmanagedType.U4)]FileShare
fileshare,
int securityattributes,
[MarshalAs(UnmanagedType.U4)]FileMode
creationdisposition,
int flags,
IntPtr template);
}
Well that's the problem. RAPI is a desktop set of APIs. If you want
to
create or open a file, call CreateFile.And with managed code, use one
of
the
classes in System.IO, which is what
they're for.
--
Chris Tacke
OpenNETCF Consulting
Managed Code in the Embedded Worldwww.opennetcf.com
--
No this code is not running on the pc, i am using an imate device to
test this.. i have activesync installed though
Is ActiveSync installed on the PC (this is code running on the PC,
right?)
--
Chris Tacke
OpenNETCF Consulting
Managed Code in the Embedded Worldwww.opennetcf.com
--
messagenews:[email protected]...

I was trying to use the CeCreateFile function of rapi.dll in my
c#
code.. All i am trying to do in the program bellow is to create a
file..
but when i try to run the program i get a
MissingMethodException -
"Can't find PInvoke DLL 'rapi.dll'."
Is there something wrong with code -- and do we need to place
rapi.dll
at some specific location(currently i have placed in the same
folder
where i am deploying my project).
I am not very familiar with P/Invoke.. you help will be greatly
appreciated.

static void Main()

MessageBox.Show("Before Invoking");
short FILE_ATTRIBUTE_NORMAL = 0x80;
short FILE_ATTRIBUTE_DIRECTORY = 0x10;
short FILE_ATTRIBUTE_TEMPORARY = 0x100;
uint GENERIC_READ = 0x80000000;
uint GENERIC_WRITE = 0x40000000;
short CREATE_NEW = 1;
short CREATE_ALWAYS = 2;
short OPEN_EXISTING = 3;
int handle = CeCreateFile("xxxx", GENERIC_WRITE, 0, 0,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
MessageBox.Show("Card handle is - " + handle);
// End of card related code //

[StructLayout(LayoutKind.Sequential)]
public struct OSVERSIONINFO
{
public int dwOSVersionInfoSize;
public int dwMajorVersion;
public int dwMinorVersion;
public int dwBuildNumber;
public int dwPlatformId;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
public string szCSDVersion;
}
[StructLayout(LayoutKind.Sequential)]
public struct RAPIINIT
{
int cbSize;
int heRapiInit;
int hrRapiInit;
}
[StructLayout(LayoutKind.Sequential)]
public struct SECURITY_ATTRIBUTES
{
public int nLength;
public int lpSecurityDescriptor;
public int bInheritHandle;
}
[DllImport("rapi.dll", CharSet = CharSet.Unicode)]
public static extern int CeCloseHandle(int hObject);
[DllImport("rapi.dll", CharSet = CharSet.Unicode)]
public static extern int CeCreateFile(string lpFileName,
uint
dwDesiredAccess, int dwShareMode, int lpSecurityAttributes, int
dwCreationDisposition, int dwFlagsAndAttributes, int
hTemplateFile);
[DllImport("rapi.dll", CharSet = CharSet.Unicode)]
public static extern int
CeRapiInitEx([MarshalAs(UnmanagedType.Struct)] ref RAPIINIT
pRapiInit);
[DllImport("rapi.dll", CharSet = CharSet.Unicode)]
public static extern int CeRapiInit();
[DllImport("rapi.dll", CharSet = CharSet.Unicode)]
public static extern int CeRapiUninit();
[DllImport("rapi.dll", CharSet = CharSet.Unicode)]
public static extern int CeReadFile(int hFile,
StringBuilder
lpBuffer, int nNumberOfbytesToRead, out int lpNumberOfbytesRead,
int
lpOverlapped);
[DllImport("rapi.dll", CharSet = CharSet.Unicode)]
public static extern int CeWriteFile(int hFile,
StringBuilder
lpBuffer, int nNumberOfbytesToWrite, out int
lpNumberOfbytesWritten,
int lpOverlapped);
[DllImport("rapi.dll", CharSet = CharSet.Unicode)]
public static extern int GetLastError();
[DllImport("rapi.dll", CharSet = CharSet.Unicode)]
public static extern int CeSetEndOfFile(int hFile);
[DllImport("rapi.dll", CharSet = CharSet.Unicode)]
public static extern int CeGetFileSize(int hFile, int
lpFileSizeHigh);
[DllImport("rapi.dll", CharSet = CharSet.Unicode)]
public static extern int CeGetLastError();
 
W

Wrecked

Hello Chris,
I went through opennetcf. its a wonderfull package.
But i couldnt find much information regarding DeviceIOControl.
Specifically i couldnt co-relate between the parameters of this
function in c# and that of evc++. Could u kindly let me know more about
it. Particularly about the SG_REQ structure which we use in evc++ -- i
didnt find a similar one in c#.

Regards,
Rithesh Swamy
Student,
Indian Institute Of Information Technology,
Bangalore



Yes, it's there. All of this is already done and tested in the
StreamInterfaceDriver class of the OpenNETCF SDF.

www.opennetcf.org/sdf

--
Chris Tacke
OpenNETCF Consulting
Managed Code in the Embedded Worldwww.opennetcf.com
--

Wrecked said:
Chris,
That worked perfectly.. i did change that to open_existing(it was my
fault) .. it returned an handle(which is not 1- so assume that should
be write) thanks a lot.. i just wanted to know if there are also
implementations for deviceiocontrol and CloseHandle in coredll.dll. I
did write a small code to use deviceiocontrol from coredll -- however
it always returned false. I am not very sure how to use SG_REQ
structure in c#.. any help in that direction would be great ..
let me know if u want me paste that code..
Yes, you are doing something fundamentally wrong. kernel32.dll doesn't
exist in CE. CreateFile, like almost all Win32 functions in CE, is in
coredll.dll. I'd also double check all of those enum constants to make
sure
they match what CreateFile is expecting. Also, I'm certain that DSK1
will
exist, so you should be using OPEN_EXISTING, probably not Create.
--
Chris Tacke
OpenNETCF Consulting
Managed Code in the Embedded Worldwww.opennetcf.com
--
message
Hi Chris,
I am not sure if the below code is what u suggested to do..
however i am still getting the same error.. that is "Can't find PInvoke
DLL 'kernel32.dll'.".. i am doing something fundamentally wrong???
static void Main(string[] args)
{
IntPtr ptr = CreateFile("DSK1",
FileAccess.ReadWrite,
FileShare.ReadWrite,
0,
FileMode.Create,
0,
IntPtr.Zero); //pointed out by Parrys
MessageBox.Show("the handle is - " + ptr.ToString());
}
[DllImport("Kernel32.dll")]
static extern IntPtr CreateFile(
string filename,
[MarshalAs(UnmanagedType.U4)]FileAccess
fileaccess,
[MarshalAs(UnmanagedType.U4)]FileShare
fileshare,
int securityattributes,
[MarshalAs(UnmanagedType.U4)]FileMode
creationdisposition,
int flags,
IntPtr template);
}
Well that's the problem. RAPI is a desktop set of APIs. If you want
to
create or open a file, call CreateFile.And with managed code, use one
of
the
classes in System.IO, which is what
they're for.
--
Chris Tacke
OpenNETCF Consulting
Managed Code in the Embedded Worldwww.opennetcf.com
--
message
No this code is not running on the pc, i am using an imate device to
test this.. i have activesync installed though
Is ActiveSync installed on the PC (this is code running on the PC,
right?)
--
Chris Tacke
OpenNETCF Consulting
Managed Code in the Embedded Worldwww.opennetcf.com
--
message
Hello,
I was trying to use the CeCreateFile function of rapi.dll in my
c#
code.. All i am trying to do in the program bellow is to create a
file..
but when i try to run the program i get a
MissingMethodException -
"Can't find PInvoke DLL 'rapi.dll'."
Is there something wrong with code -- and do we need to place
rapi.dll
at some specific location(currently i have placed in the same
folder
where i am deploying my project).
I am not very familiar with P/Invoke.. you help will be greatly
appreciated.
Thanks
Rithesh
static void Main()
{
MessageBox.Show("Before Invoking");
short FILE_ATTRIBUTE_NORMAL = 0x80;
short FILE_ATTRIBUTE_DIRECTORY = 0x10;
short FILE_ATTRIBUTE_TEMPORARY = 0x100;
uint GENERIC_READ = 0x80000000;
uint GENERIC_WRITE = 0x40000000;
short CREATE_NEW = 1;
short CREATE_ALWAYS = 2;
short OPEN_EXISTING = 3;
int handle = CeCreateFile("xxxx", GENERIC_WRITE, 0, 0,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
MessageBox.Show("Card handle is - " + handle);
// End of card related code //
}
[StructLayout(LayoutKind.Sequential)]
public struct OSVERSIONINFO
{
public int dwOSVersionInfoSize;
public int dwMajorVersion;
public int dwMinorVersion;
public int dwBuildNumber;
public int dwPlatformId;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
public string szCSDVersion;
}
[StructLayout(LayoutKind.Sequential)]
public struct RAPIINIT
{
int cbSize;
int heRapiInit;
int hrRapiInit;
}
[StructLayout(LayoutKind.Sequential)]
public struct SECURITY_ATTRIBUTES
{
public int nLength;
public int lpSecurityDescriptor;
public int bInheritHandle;
}
[DllImport("rapi.dll", CharSet = CharSet.Unicode)]
public static extern int CeCloseHandle(int hObject);
[DllImport("rapi.dll", CharSet = CharSet.Unicode)]
public static extern int CeCreateFile(string lpFileName,
uint
dwDesiredAccess, int dwShareMode, int lpSecurityAttributes, int
dwCreationDisposition, int dwFlagsAndAttributes, int
hTemplateFile);
[DllImport("rapi.dll", CharSet = CharSet.Unicode)]
public static extern int
CeRapiInitEx([MarshalAs(UnmanagedType.Struct)] ref RAPIINIT
pRapiInit);
[DllImport("rapi.dll", CharSet = CharSet.Unicode)]
public static extern int CeRapiInit();
[DllImport("rapi.dll", CharSet = CharSet.Unicode)]
public static extern int CeRapiUninit();
[DllImport("rapi.dll", CharSet = CharSet.Unicode)]
public static extern int CeReadFile(int hFile,
StringBuilder
lpBuffer, int nNumberOfbytesToRead, out int lpNumberOfbytesRead,
int
lpOverlapped);
[DllImport("rapi.dll", CharSet = CharSet.Unicode)]
public static extern int CeWriteFile(int hFile,
StringBuilder
lpBuffer, int nNumberOfbytesToWrite, out int
lpNumberOfbytesWritten,
int lpOverlapped);
[DllImport("rapi.dll", CharSet = CharSet.Unicode)]
public static extern int GetLastError();
[DllImport("rapi.dll", CharSet = CharSet.Unicode)]
public static extern int CeSetEndOfFile(int hFile);
[DllImport("rapi.dll", CharSet = CharSet.Unicode)]
public static extern int CeGetFileSize(int hFile, int
lpFileSizeHigh);
[DllImport("rapi.dll", CharSet = CharSet.Unicode)]
public static extern int CeGetLastError();
}
 
G

Guest

DeviceIoControl is specifically defined and wrapped in the
OpenNETCF.IO.StreamInterfaceDriver class.


--
Chris Tacke
OpenNETCF Consulting
Managed Code in the Embedded World
www.opennetcf.com
--


Wrecked said:
Hello Chris,
I went through opennetcf. its a wonderfull package.
But i couldnt find much information regarding DeviceIOControl.
Specifically i couldnt co-relate between the parameters of this
function in c# and that of evc++. Could u kindly let me know more about
it. Particularly about the SG_REQ structure which we use in evc++ -- i
didnt find a similar one in c#.

Regards,
Rithesh Swamy
Student,
Indian Institute Of Information Technology,
Bangalore



Yes, it's there. All of this is already done and tested in the
StreamInterfaceDriver class of the OpenNETCF SDF.

www.opennetcf.org/sdf

--
Chris Tacke
OpenNETCF Consulting
Managed Code in the Embedded Worldwww.opennetcf.com
--

Chris,
That worked perfectly.. i did change that to open_existing(it was my
fault) .. it returned an handle(which is not 1- so assume that should
be write) thanks a lot.. i just wanted to know if there are also
implementations for deviceiocontrol and CloseHandle in coredll.dll. I
did write a small code to use deviceiocontrol from coredll -- however
it always returned false. I am not very sure how to use SG_REQ
structure in c#.. any help in that direction would be great ..
let me know if u want me paste that code..
Yes, you are doing something fundamentally wrong. kernel32.dll
doesn't
exist in CE. CreateFile, like almost all Win32 functions in CE, is in
coredll.dll. I'd also double check all of those enum constants to
make
sure
they match what CreateFile is expecting. Also, I'm certain that DSK1
will
exist, so you should be using OPEN_EXISTING, probably not Create.
--
Chris Tacke
OpenNETCF Consulting
Managed Code in the Embedded Worldwww.opennetcf.com
--
Hi Chris,
I am not sure if the below code is what u suggested to do..
however i am still getting the same error.. that is "Can't find
PInvoke
DLL 'kernel32.dll'.".. i am doing something fundamentally wrong???
static void Main(string[] args)
{
IntPtr ptr = CreateFile("DSK1",
FileAccess.ReadWrite,
FileShare.ReadWrite,
0,
FileMode.Create,
0,
IntPtr.Zero); //pointed out by Parrys
MessageBox.Show("the handle is - " + ptr.ToString());
}
[DllImport("Kernel32.dll")]
static extern IntPtr CreateFile(
string filename,
[MarshalAs(UnmanagedType.U4)]FileAccess
fileaccess,
[MarshalAs(UnmanagedType.U4)]FileShare
fileshare,
int securityattributes,
[MarshalAs(UnmanagedType.U4)]FileMode
creationdisposition,
int flags,
IntPtr template);
}
Well that's the problem. RAPI is a desktop set of APIs. If you
want
to
create or open a file, call CreateFile.And with managed code, use
one
of
the
classes in System.IO, which is what
they're for.
--
Chris Tacke
OpenNETCF Consulting
Managed Code in the Embedded Worldwww.opennetcf.com
--
No this code is not running on the pc, i am using an imate device
to
test this.. i have activesync installed though
On Oct 30, 5:03 pm, "<ctacke/>" <ctacke[@]opennetcf[dot]com>
wrote:
Is ActiveSync installed on the PC (this is code running on the
PC,
right?)
--
Chris Tacke
OpenNETCF Consulting
Managed Code in the Embedded Worldwww.opennetcf.com
--
messagenews:[email protected]...

I was trying to use the CeCreateFile function of rapi.dll in
my
c#
code.. All i am trying to do in the program bellow is to
create a
file..
but when i try to run the program i get a
MissingMethodException -
"Can't find PInvoke DLL 'rapi.dll'."
Is there something wrong with code -- and do we need to place
rapi.dll
at some specific location(currently i have placed in the same
folder
where i am deploying my project).
I am not very familiar with P/Invoke.. you help will be
greatly
appreciated.

static void Main()

MessageBox.Show("Before Invoking");
short FILE_ATTRIBUTE_NORMAL = 0x80;
short FILE_ATTRIBUTE_DIRECTORY = 0x10;
short FILE_ATTRIBUTE_TEMPORARY = 0x100;
uint GENERIC_READ = 0x80000000;
uint GENERIC_WRITE = 0x40000000;
short CREATE_NEW = 1;
short CREATE_ALWAYS = 2;
short OPEN_EXISTING = 3;
int handle = CeCreateFile("xxxx", GENERIC_WRITE, 0,
0,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
MessageBox.Show("Card handle is - " + handle);
// End of card related code //

[StructLayout(LayoutKind.Sequential)]
public struct OSVERSIONINFO
{
public int dwOSVersionInfoSize;
public int dwMajorVersion;
public int dwMinorVersion;
public int dwBuildNumber;
public int dwPlatformId;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst =
128)]
public string szCSDVersion;
}
[StructLayout(LayoutKind.Sequential)]
public struct RAPIINIT
{
int cbSize;
int heRapiInit;
int hrRapiInit;
}
[StructLayout(LayoutKind.Sequential)]
public struct SECURITY_ATTRIBUTES
{
public int nLength;
public int lpSecurityDescriptor;
public int bInheritHandle;
}
[DllImport("rapi.dll", CharSet = CharSet.Unicode)]
public static extern int CeCloseHandle(int hObject);
[DllImport("rapi.dll", CharSet = CharSet.Unicode)]
public static extern int CeCreateFile(string
lpFileName,
uint
dwDesiredAccess, int dwShareMode, int lpSecurityAttributes,
int
dwCreationDisposition, int dwFlagsAndAttributes, int
hTemplateFile);
[DllImport("rapi.dll", CharSet = CharSet.Unicode)]
public static extern int
CeRapiInitEx([MarshalAs(UnmanagedType.Struct)] ref RAPIINIT
pRapiInit);
[DllImport("rapi.dll", CharSet = CharSet.Unicode)]
public static extern int CeRapiInit();
[DllImport("rapi.dll", CharSet = CharSet.Unicode)]
public static extern int CeRapiUninit();
[DllImport("rapi.dll", CharSet = CharSet.Unicode)]
public static extern int CeReadFile(int hFile,
StringBuilder
lpBuffer, int nNumberOfbytesToRead, out int
lpNumberOfbytesRead,
int
lpOverlapped);
[DllImport("rapi.dll", CharSet = CharSet.Unicode)]
public static extern int CeWriteFile(int hFile,
StringBuilder
lpBuffer, int nNumberOfbytesToWrite, out int
lpNumberOfbytesWritten,
int lpOverlapped);
[DllImport("rapi.dll", CharSet = CharSet.Unicode)]
public static extern int GetLastError();
[DllImport("rapi.dll", CharSet = CharSet.Unicode)]
public static extern int CeSetEndOfFile(int hFile);
[DllImport("rapi.dll", CharSet = CharSet.Unicode)]
public static extern int CeGetFileSize(int hFile, int
lpFileSizeHigh);
[DllImport("rapi.dll", CharSet = CharSet.Unicode)]
public static extern int CeGetLastError();
 

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