Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / October 2007

Tip: Looking for answers? Try searching our database.

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

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Peter - 16 Oct 2007 13:28 GMT
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
Nicholas Paldino [.NET/C# MVP] - 16 Oct 2007 14:24 GMT
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.

Signature

         - Nicholas Paldino [.NET/C# MVP]
         - mvp@spam.guard.caspershouse.com

> Hi
> I write a POS (point-of-sale) applic. until now i use c# code to open
[quoted text clipped - 31 lines]
> Thank you
> Peter
Peter - 16 Oct 2007 15:30 GMT
On 16 Okt., 15:24, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guard.caspershouse.com> wrote:
> Peter,
>
[quoted text clipped - 53 lines]
>
> - Zitierten Text anzeigen -

Thank you.
Peter

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.