473,837 Members | 2,012 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

1 New Member
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 1063

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

Similar topics

12
2475
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 drawing time. Time is measured in clock ticks (from QueryPerformanceCounter() API). The processor resolution (QueryPerformanceFrequency()) for my
6
1900
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. Searching - I found many new words :-) like .Net wrapper, Assembly... but I couldn't find a clear cut answer -
1
1974
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 they do from win32 api. Thanks. Vakkas
3
2441
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
1396
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 drives between production and release machines. Thanks Regards
46
3790
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 time. Therefore, my assumption that using Declare statement or DllImport attribute is NOT an option in such a case. I can use LoadLibrary() and GetProcAddress() from Kernel32 to get the addreses, but is there a way to actually call an API method...
2
4529
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 the files in use and the names of the users accessing them). I have also found the NetConnectionEnum call (returns the name of the computer that is accessing a share). I do not see any way of correlating the data that these two api calls...
2
1234
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 but IDE VS.NET2005 doesn't allow me to do the same. Although those were DLLs but VS still throws exception and prompt that only DLLs can be referred. I am worndering if it at all possible. Any help would be greatly helpful for me.
1
1180
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 my own database which is programmed via MsAccess. How would I go about communicating to the dll via VBA, Thanks,
0
10890
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10581
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10634
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10279
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7819
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5855
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4479
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4053
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3127
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.