473,320 Members | 1,883 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,320 software developers and data experts.

accessing c++ api's (dlls) on c#

1
hi everyone.. Im having trouble in accessing an api from c++ dll using c# platform.. I would like to retreive data from this api... I think im lost
pls help me...
Expand|Select|Wrap|Line Numbers
  1. //this is the api created from visual c++ taht i would like to access
  2. //using c# platform..
  3.  
  4. bool WINAPI SCSYS_GetDeviceInfo( int Type, int Index, void *DevInf )
  5.  
  6.  
  7.     typedef struct _SCDeviceInfo
  8.  
  9.     {
  10.  
  11.         char    DriverName[80];      
  12.         char    DriverNameL[80];    
  13.         int     SlotNumber;     
  14.         int     DeviceIndex;     
  15.         WORD    Enable;      
  16.         WORD    DeviceID;   
  17.         WORD    VendorID;  
  18.         WORD    Revision;   
  19.         DWORD   VersionID;
  20.         DWORD   xxx1[2];
  21.         DWORD   PciBaseMemAdr;
  22.         DWORD   PciBaseIOAdr;   
  23.         DWORD   BaseMemSize;  
  24.         DWORD   CrmsIocTop;      
  25.         DWORD   CrmsIocSize;     
  26.         DWORD   ProgramCode;    
  27.         DWORD   ErrorCode;         
  28.         DWORD   xxx2[3];
  29.  
  30.     } SCDeviceInfo;
  31.  
  32. //here is my c# implementation...
  33.  
  34.         [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Ansi,Pack=2)]
  35.         public struct SCDeviceInfo //class DevInfo
  36.         {
  37.  
  38.             [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 80)]
  39.             public string DriverName;
  40.  
  41.             [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 80)]
  42.             public string DriverNameL;
  43.             public int SlotNumber;
  44.             public int DeviceIndex;
  45.             public System.UInt16 Enable;
  46.             public System.UInt16 DeviceID;
  47.             public System.UInt16 VendorID;
  48.             public System.UInt16 Revision;
  49.             public System.UInt32 VersionID;
  50.            [MarshalAs(UnmanagedType.U4,SizeConst=2)] public UInt32 xxx1;
  51.             public System.UInt32 PciBaseMemAdr;
  52.             public System.UInt32 PciBaseIOAdr;
  53.             public System.UInt32 BaseMemSize;
  54.             public System.UInt32 CrmsIocTop;
  55.             public System.UInt32 CrmsIocSize;
  56.             public System.UInt32 ProgramCode;
  57.             public System.UInt32 ErrorCode;
  58.             [MarshalAs(UnmanagedType.U4, SizeConst = 3)] public UInt32 xxx2;
  59.  
  60.   }
  61.  
  62.  
  63.  
  64.    SCDeviceInfo sc = new SCDeviceInfo();
  65.    IntPtr pInfo = Marshal.AllocHGlobal(Marshal.SizeOf(sc));
  66.    SCSYS_GetDeviceInfo(1, 0, pInfo);
  67.    sc.DriverName = "aloha";
  68.    Marshal.StructureToPtr(sc, pInfo, false);
  69.    SCDeviceInfo NewVal;
  70.    NewVal = (SCDeviceInfo)Marshal.PtrToStructure(pInfo, typeof(SCDeviceInfo));
  71.    MessageBox.Show(NewVal.DriverName.ToString());
  72.  
problem is I cant retrive any value in my structure... pls help me... :(
Nov 9 '07 #1
0 1037

Sign in to post your reply or Sign up for a free account.

Similar topics

12
by: Gustavo L. Fabro | last post by:
Greetings! Getting straight to the point, here are the results of my experiment. I've included my comments and questions after them. The timing: (The total time means the sum of each line's...
6
by: rakefet | last post by:
Hi. I'm really new to this world of .Net so your help would be most appreciated... We have API and COM interfaces developed in c. We would also like to supply a .net interface to our clients....
1
by: Vakkaas | last post by:
Hi, Is there a way to create a dll in .Net like win32 API dll's. My concern is that i want to create DLL's so that other tools like Powerbuilder may be able to call functions from that dll like...
3
by: John | last post by:
Hi What are the advantages of storing ones class project dlls in gac? How can one access these dlls? Thanks Regards
7
by: John | last post by:
Hi I have a class dll which I would ideally like to reside in \\ folder. My question is; How are my vb.net apps to reference and use this dll specially since the \\ folder can reside on different...
46
by: Usenet User | last post by:
I need to be able to call the same API function from VB, which will reside in different DLLs. While all of the functions have the same signature and name, DLL file names are not known at compile...
2
by: Vincent | last post by:
I have been trying to find some API routines that will allow me to determine the name of the computer that is accessing a file on a server. I have found the NetFileEnum call (returns the names of...
2
by: Amit Bhatnagar | last post by:
Hi, We have couple of assemblies developed in framework 2.0, we need to include them in project reference in our one of the application which was dewveloped in framework 1.1. I trie to ad them...
1
by: bg_ie | last post by:
Hi, My company has a database which I need to read from my database now and again. This db can only be read via a dll written in C#. I need to read data from this database and popule a table in...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.