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

import unmanaged dll into c sharp

2
hi,
i'm trying to import an unmanaged dll into a c# application. The dll is given to me but i'm new with dll import thing and having some troubles importing it. Dll comes with a pdf file which describes the functions but all parameters and types are c++ type and i need to write them as c# types. i tried "Dllimport" but i think i couldn't write the correct parameter types. Functions use handles and pointers which doesn't make it easier for me. If someone can write the correct syntax and usage of the functions, i will be most grateful. im writing the functions as described in the pdf:

Comm_Init function: Initializes the DLL for first time loading. Gets a window handle (HWND) as
parameter.

Expand|Select|Wrap|Line Numbers
  1. void Comm_init
  2. (
  3. HWND wndHandle
  4. );
Comm_create function: creates a TCP communication to device using ip address and TCP port number.

Expand|Select|Wrap|Line Numbers
  1. TCommHnd Comm_create
  2. (
  3. char *address,
  4. int port,
  5. mEventHandler eventHandler,
  6. int synchComm
  7. );
  8.  
these are the main functions i need to figure out. And there is a type definition (TCommHnd) which described as "typedef void* TCommHnd;" .

Comm_init function initializes DLL, for further usage. It is not a thread safe
function, it should be called one time during the operation of the DLL. All functions except
Comm_init are thread safe functions, for different TCommHnd’s.

I wrote the type definitions and functions into a class file in my project and tried to use the functions in the program. But i think i made some mistakes either in definitions or in usage. I dont really know anything about dllimport and handles but i really need to figure this one out. should i use LoadLibrary and GetProcAddress? Any help will be appreciated,

Best regards
Apr 24 '10 #1
3 2902
tlhintoq
3,525 Expert 2GB
TIP: When you first created your question you were asked to wrap your code with [code] tags.

It really does help a bunch. Look how much easier it is to read now that someone has done it for you. Its the button with a '#' on it. More on tags. They're cool. Check'em out.
Apr 25 '10 #2
tlhintoq
3,525 Expert 2GB
Are you using this DLL because you need *other* functions as well, or because you thought it would be an easy shortcut to TCP/IP communication?

If you don't need other functions that are in the DLL, it might be a lot cleaner for your application to just to TCP/IP within C#

There is an exampel TCP client/server on the MSDN
http://code.msdn.microsoft.com/tcpclientandserverEx
Apr 25 '10 #3
rorybr
2
I'm using this dll because i need to use other functions of the dll... dll is not just a TCP/IP dll... it creates modbusTCP/IP communication with some specific devices... thats why i have to use it
Apr 26 '10 #4

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

Similar topics

2
by: David Vestal | last post by:
I need to import an unmanaged DLL (not COM or .NET, just a plain DLL), but there's a caveat. I don't know its name at compile-time. I know the functions and function signatures that are in it,...
4
by: Hai Nguyen | last post by:
I'm learning C sharp and do not like vb much. I'm creatiing a wepage using panel to test myself. I tried to use these code below, which is written in VB, and to transform them to c sharp but I got...
3
by: Mark Urish | last post by:
Is there a way to import data from an unmanaged dll? For example, unmanaged.dll: __declspec(dllexport) int unmanagedErrno; managed.cs: class Managed { //this doesn't work:
0
by: Tim | last post by:
Hi, I am facing a problem with a legacy application a part of which is being ported to VS 2005. I have a VB exe 'A.Exe' (legacy code) calling methods from a C-Sharp dll say, 'C.dll', which in...
2
by: amirbehzadan | last post by:
Hello, I am writing some C++ classes and want to export them as .dll files so other users can import them and use the methods I have provided in those classes. I have two types of classes :...
3
by: amirbehzadan | last post by:
Hello, I am writing some C++ classes and want to export them as .dll files so other users can import them and use the methods I have provided in those classes. I have two types of classes :...
1
by: Praveen | last post by:
Have a common function in Javascript which do transform for all .xsl's. XSL object is loaded like this. var xslobj=new ActiveXObject("MSXML2.FreeThreadedDOMDocument.4.0"); xslobj.async = false;...
4
by: Zytan | last post by:
I have VB code that shows how to import a DLL function. I compiled it. I used .NET Reflector to see the C# code, and it shows this: private static extern bool MethodName( ref string...
3
by: MichalSody | last post by:
How cann I import & use these function from an old C++ dll ? Only this, I've got are these two signatures of function I wannt use in my C# app. DllExport int DLLAPI drawImage( char...
1
by: madbat87 | last post by:
Hi, I'm trying to import code from a c++ unmanaged dll in a c# project. In the dll there's a class named Connection, but the dll exposes only 2 methods (outside the class): - HBITMAP...
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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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,...

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.