Dll Import "Translate C++ --> C#'

P

Peter

Hi
I write a POS (point-of-sale) applic. until now i use c# code to open
the cash-drawer.
But now there is a new hardware and i have just a c++ code snip to do
this.

Please can somebody help me to translate this:

#include <windows.h>
// szDeviceName ->Device Driver Name
// CTL_ID-> Control Code

__declspec( dllimport ) DWORD WINAPI DeviceControl(LPSTR szDeviceName,
DWORD CTL_ID);
__declspec( dllimport ) DWORD WINAPI PortwellGetCashDrawerStatus(LPSTR
szDeviceName,DWORD CTL_ID);

void main()
{
DWORD ret; // 0 -> success, -1 -> create file
failed, -2 -> device io control failed

ret = DeviceControl("\\\\.\\FEC_cash", 10);
......
ret = PortwellGetCashDrawerStatus("\\\\.\\FEC_cash", 11);
....

into C#

is LPSTR a byte[] ?
is DWORD = UInt32 ?
is "\\\\.\\FEC_cash" = @"\\.\FEC_cash"


Thank you
Peter
 
N

Nicholas Paldino [.NET/C# MVP]

Peter,

Here are your declarations that you will use:

[DllImport("dlllocation.dll")]
static extern int DeviceControl([MarshalAs(UnmanagedType.LPStr)] string
szDeviceName, int CTL_ID);

You have to replace "dlllocation.dll" with the name of the dll which the
functions are exported from. This dll has to be located by the LoadLibrary
function if it is not an absolute path. Additionally, if the functions call
SetLastError then you have to set the SetLastError property on the DllImport
attribute.

All of this applies to the PortwellGetCashDrawerStatus function as well.
 
P

Peter

Peter,

Here are your declarations that you will use:

[DllImport("dlllocation.dll")]
static extern int DeviceControl([MarshalAs(UnmanagedType.LPStr)] string
szDeviceName, int CTL_ID);

You have to replace "dlllocation.dll" with the name of the dll which the
functions are exported from. This dll has to be located by the LoadLibrary
function if it is not an absolute path. Additionally, if the functions call
SetLastError then you have to set the SetLastError property on the DllImport
attribute.

All of this applies to the PortwellGetCashDrawerStatus function as well.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)




Hi
I write a POS (point-of-sale) applic. until now i use c# code to open
the cash-drawer.
But now there is a new hardware and i have just a c++ code snip to do
this.
Please can somebody help me to translate this:
#include <windows.h>
// szDeviceName ->Device Driver Name
// CTL_ID-> Control Code
__declspec( dllimport ) DWORD WINAPI DeviceControl(LPSTR szDeviceName,
DWORD CTL_ID);
__declspec( dllimport ) DWORD WINAPI PortwellGetCashDrawerStatus(LPSTR
szDeviceName,DWORD CTL_ID);
void main()
{
DWORD ret; // 0 -> success, -1 -> create file
failed, -2 -> device io control failed
ret = DeviceControl("\\\\.\\FEC_cash", 10);
.....
ret = PortwellGetCashDrawerStatus("\\\\.\\FEC_cash", 11);
...
is LPSTR a byte[] ?
is DWORD = UInt32 ?
is "\\\\.\\FEC_cash" = @"\\.\FEC_cash"
Thank you
Peter- Zitierten Text ausblenden -

- Zitierten Text anzeigen -

Thank you.
Peter
 

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