Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Linking vb GUI to a C dll 1

Status
Not open for further replies.

Jon4747

Programmer
Aug 22, 2001
234
CA
I have created a vb GUI & a C dll but can't get them to link .I've tried Project -> references -> browse -> mydll.dll and I get an error "Can't add a reference to specified file" Any suggestion ? Please help.

Jon
 
You need to declare the function from your dll the way that you declare a function from a windows API. Then you can call the function from your VB code.

In this example from VB Programmers Journal the VB program is using a C++ dll.

Private Declare Sub ApplyXOR Lib "c:\VBEncrypt\debug\VBEncrypt.dll" (ByVal strData As String, ByVal lngLen as Long)

Then in code the function ApplyXOR is called like any other.

A good article on using C++ to enhance VB is available in VBPJ January 2001.
 
Thank-you Theologian

But what if I want the dll as a reference, to be included in the excuteable file ? Would I be better off creating an .ocx file ?

Jon
 
I'm no help to you there. I saw your post and thought immediately of the article from VBPJ- so I could help out w/that but you have now seen the extent of my knowledge in regards to using C++ with VB.
 
If u want to reference it, you need to make it a COM object and not a regular DLL.
 
Thank-you Tuan3249 I think I can make that work

Jon
 
If you don't want to make your DLL a COM object, you can leave it as an ordinary C dll, and export the functions you want to call. The MS documentation says you can use the compiler pragma __declspec(dllexport), but it doesn't work when called by VB. You must use the old-school way of declaring your function as WINAPI, and including the function name in a .DEF file you make part of your VC++ project.

Chip H.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top