473,395 Members | 1,443 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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

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

Oct 16 '07 #1
2 5322
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]
- mv*@spam.guard.caspershouse.com

"Peter" <pR****@procom-gmbh.comwrote in message
news:11**********************@i38g2000prf.googlegr oups.com...
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
Oct 16 '07 #2
On 16 Okt., 15:24, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guard.caspershouse.comwrote:
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]
- m...@spam.guard.caspershouse.com

"Peter" <pRu...@procom-gmbh.comwrote in message

news:11**********************@i38g2000prf.googlegr oups.com...
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- Zitierten Text ausblenden -

- Zitierten Text anzeigen -
Thank you.
Peter

Oct 16 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: leroybt.rm | last post by:
I don't understand why this does not work: <FILE1> test1.py #Import Packages import string # data=0 data=data+1
35
by: Will Stuyvesant | last post by:
Here is a question about list comprehensions . The question is dumb because I can do without ; but I am posing the question because I am curious. This: >>> data = ,,] >>> result = >>> for...
10
by: John Tiger | last post by:
Can anybody have idea about the difference between #include <iostream.h> and #include <iostream>. Is later one valid statement on any compiler. I tried compiling on MSVC second statement give...
1
by: Bernd Oninger | last post by:
As far as I know one could use other xsd schemas with the import and the xlink feature. What are the differences (beside the syntax)? Bernd
1
by: Christian Schmidbauer | last post by:
Hello! I prepare my XML document like this way: ------------------------------------------------------- PrintWriter writer; Document domDocument; Element domElement; // Root tag
7
by: stefano | last post by:
Hi all, I hopen a new empty window from js code: var win = window.open("","debug","width=500,height=300,modal,dialog,resizable"); and I add some element to the new window:...
5
by: David Harris | last post by:
I am developing a type of data warehouse. Basically, we have 20 client survey machines that are each separated from the server by space and lack of network. Yet both need to speak to each other...
2
by: john | last post by:
I have 400 different Excel-spreadsheetfiles, same structure, all with only one record in it, and all residing in the same folder. Every now and then new Excel files are being added. In my Access...
7
by: mark | last post by:
Hi All, Apologies for the newbie question but I've searched and tried all sorts for a few days and I'm pulling my hair out ; Please feel free to teach me to suck eggs because it's all new to me...
4
by: pdlemper | last post by:
Have carefully installed Python 2.5.1 under XP in dir E:\python25 . ran set path = %path% ; E:\python25 Python interactive mode works fine for simple arithmetic . Then tried >> import math Get...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.