Discussion Locked

How to use our Dll as like API Library

0 helpful
9 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

In Visual Basic,

We can use API function
by following manner.

Private declare GetCursorPps Lib "User32.dll"(...)

Similarly , I have Created A.dll

How to call a method of A.dll with out
giving the reference in "project References"
like API.

I have tried this by following manner.

Private declare method Lib "A.dll" (...)

But it raises the following error.

'Entry Point not found ' when i am trying to
call the method of A.dll

Is it possible to do like this ? ifyes how ?

9 replies

by wayne m.

Refer to Microsoft's COM. There are several excellent books on how to implement COM in VB. COM provides a common method to import and call methods from DLLs.

by glen_mcleod

This has nothing to do with COM, it's the C/C++ compiler (I'm assuming C/C++, I've had this happen to me).

When you compile in C/C++, the function names get mangled. C/C++ doesn't use the function names to call the functions, it uses the resource ID. VB tries to call it by name and can't find it because it's mangled.

There are 2 ways around this:

Write a intermediate C/C++ .dll that exposes it's unmangeled function names to VB and calls the original .dll through native C/C++ calls.I've never done it myself, but I've worked on projects where it was done by someone else because we didn't have the source code to the original .dll.

If you have the source code, then use the option in C/C++ to build it as a COM object using ATL. Then you can call it from VB directly.

Glen

by dushy_ant

Dear Mr. Murthy

API basically means dealing with the hardware.
The dll's which we use in VB are basically running under Windows. If we want to use our own dll as an API we will have to make it available as Windows Operating system dll which is not possible at user level.

The dll must have at least one instance of it running under the operating system. As your API is not available to the operating system, it cannot be instanciated by Public Declare statement.

by rrv

There is solution for this MSDN help CD.
While writing DLL in VB, make it global instantiating in property of the class. all the methods in the class should be public. be sure about the Byref and Byval. While writing the dll add a project to it and check all the methods in it with the added project. Remove the project and compile the dll. After creating dll, check regsvr32.exe help to register the dll. Check "implements" keyword also if you need it. while declaring the API, which is a method or public function write the path of the dll-not only the dll. Then it should work.
All the best
RV

This discussion is closed to new replies.