justplainsoccer Posted January 8, 2005 Posted January 8, 2005 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 Quote
Diesel Posted January 8, 2005 Posted January 8, 2005 Compile it using VSC++ into a DLL, add the dll as a Reference to your vb.net project and you can use the functions in the dll. Quote
Wile Posted January 8, 2005 Posted January 8, 2005 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 ;). Quote Nothing is as illusive as 'the last bug'.
Talyrond Posted January 10, 2005 Posted January 10, 2005 (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 January 10, 2005 by Talyrond Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.