Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

does anyone know how to wrap up c code to be used in vb.net? i really dont know what exactly i am talking about but i read that someone "wrapped up c code to call from java" or something like that. Any ideas?

 

Thanks.

Aaron

Posted

One remark on Diesel: that will only work if it is compiled as a managed assembly (it is compiled for .Net) or if it is a COM object. If it is an old fashioned linked library like most of the Windows API, you need to import the methods with DllImport.

 

If they used an actual 'wrapper' than it usually means that it is an old fasioned library that needs to be imported. The wrapper class than takes care of all the iritating/difficult handling of the DLL, the rest of the code only uses the relatively easy wrapper.

 

Basicly like a wrapped up present, it looks good on the outside, just as long you don't open it and find the old shoe inside ;).

Nothing is as illusive as 'the last bug'.
Posted (edited)

Hi, I�ve just completed such a task so I hope I can shed some more light. As Wile suggested I would go the DllImport route.

 

I assume you have the sorce code for the �C� routines. I downloaded VS C++ beta express, it�s free and works a treat!

Create a Win32 Dll console app. Use .cpp file extensions.

 

The functions that you want access to, add the following in front of the prototypes:

 

extern "C" __declspec(dllexport)

 

eg:

 

extern "C" __declspec(dllexport) int functionName ( int variable );

 

 

In your VB project, declare the function like this:

 

Imports System.Runtime.InteropServices

<DllImport("yourCdll.dll")> _
Public Shared Function functionName(ByVal variable as int) As Integer
End Function

 

Now you can call the function as normal!

 

This topic comes under the banner of �Plateform Invoke" you can do some internet searches

 

Hope this helps

Edited by Talyrond

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...