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

importing from an unmanaged DLL

Hi

I know this issue have been here before, but im struggeling with my problem.
Im trying to import an unmanaged DLL from C to C#.

From the headerfile i have the following declaration:

extern "C"_declspec(dllexport)
long _stdcall TCatIoGetInputPtr( unsigned short nPort, void** ppInput, int nSize );

with the following variable description:

ppInp:
Address of the pointer to get the address of the output buffer. If TCatIoGetInputPtr succeeds, the pointer is initialized to the address of the input buffer.



I thought i could use something like:

[DllImport("TCatIoDrv.dll", SetLastError = true)]
public static extern int TCatIoGetInputPtr(ushort nPort, byte [] ppInput,
int nSize);

But it doesnt seem to work.


Any one who could help ?


Thanks,

Nikolaj
Feb 26 '08 #1
5 1448
Plater
7,872 Expert 4TB
Do you have .def file in your unmanaged DLL?

I have one for my "TestFixtureDLL.dll" that looks something like this:
Expand|Select|Wrap|Line Numbers
  1. ; TestFixtureDLL.def : Declares the module parameters for the DLL.
  2.  
  3. LIBRARY      "TestFixtureDLL"
  4.  
  5. EXPORTS
  6.     ; Explicit exports can go here
  7.     DllCanUnloadNow     PRIVATE
  8.     DllGetClassObject   PRIVATE
  9.     DllRegisterServer   PRIVATE
  10.     DllUnregisterServer PRIVATE
  11.     writelocalbus
  12.     readlocalbus
  13.     swritelocalbus
  14.     sreadlocalbus
  15.  
The four functions I want available to managed code were:
writelocalbus
readlocalbus
swritelocalbus
sreadlocalbus
NOTE: That is not their function defs, for instance writelocalbus is really:
Expand|Select|Wrap|Line Numbers
  1. bool writelocalbus(UINT16 Offset, UINT16 Data)
  2. {
  3. //....
  4. }
  5.  
The other four functions were required by the DLL to be used in managed code (I think, maybe they are just general DLL requirements)
Feb 26 '08 #2
I only have the header file for the function calls, so im not able to see what is in the .DLL.

My problem is what to do with the double void pointer in C# ? Can I just use a bytearray?
Feb 26 '08 #3
Plater
7,872 Expert 4TB
My problem is what to do with the double void pointer in C# ? Can I just use a bytearray?
I didn't even see that void **, you might ahve to read into the Marshalling section in MSDN about what to do with void **. This goes beyond my realm of unamanged DLL usage.
Feb 26 '08 #4
Yea have been there looking for solutions, but cant find much specifically about my issue..
Feb 28 '08 #5
Plater
7,872 Expert 4TB
Have you tried using IntPrtr for void** ?
Feb 28 '08 #6

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

Similar topics

7
by: Timothy Shih | last post by:
Hi, I am trying to figure out how to use unmanaged code using P/Invoke. I wrote a simple function which takes in 2 buffers (one a byte buffer, one a char buffer) and copies the contents of the byte...
5
by: Howard Kaikow | last post by:
I have files to build a C project, including the makefile, what's the easiest way to import the project into C and C# in VS .NET Professional? I have both VS .NET 2002 and 2003. I have nothing...
2
by: Filippo Bettinaglio | last post by:
hi, I have a COM object and I need it to import the comobject.dll into my VC++ 2005 application. I was able to do it easly in C Sharp but in VC++ 2005? Many Thanks Filippo
0
by: k.boyadjiev | last post by:
Hi, I am writing a software under .NET, what I need is a way to use my assemblies from within unamanaged c++ or VB6 projects. Is there a way that can help me import .NET assemblies within...
3
by: Kamen | last post by:
Hi, I am writing a software under .NET, what I need is a way to use my assemblies from within unamanaged c++ or VB6 projects. Is there a way that can help me import .NET assemblies within...
3
by: abdul | last post by:
I have imported C++ dll in C#. But i am getting this error. "An unhandled exception of type 'System.EntryPointNotFoundException' occurred in ConsoleApplication.exe Additional information: Unable to...
4
by: Duncan Smith | last post by:
I have a VS2005 C++ MFC project which #imports a type library. The goal is to introduce some managed code eventually, but for starters I just need to set the /clr compiler option and build the...
0
by: Lukasz Ledochowski | last post by:
Hi! I have a problem with importing unmanaged dll in my application. When I use DllImport, everything works fine. But I want to use dynamically created dll path, so I import LoadLibrary first...
1
by: raghaw | last post by:
Hi, I have a Project implemented in unmanaged C++ .There are various header files of it.I want to know how to use the header files of this project into my one of C++/CLI project???
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.