DLL declaration...

Hi all

I have a fuction in a DLL which I would like to use in my VC++ 6 application. Can someone tell me how I can declare the fucntion in order to use it?

Eg:
Myfunc (a: PChar; b: Boolean) returns an interger.

Regards
Keith
LVL 1
keithcslAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

nietodCommented:
I suspect that the function was not written in C++, right? (it looks like pascal).  this is very important.  If it was written in C++, there might be some problems.

Try

__declspec(dllimport) extern "C" void MyFunc(char *a,bool b);

Note, I'm not sure how to "convert" the boolean to C/C++.  You should check with the compiler used to generate the DLL to see how it represents a Boolean, then from there decide how the represent that in C,   I used type bool, but that might not be right.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
keithcslAuthor Commented:
nietod

Yes, it was written in Pascal. The more complete declaration is:

function MyFunc (a: PChar; b: Boolean; c: PChar; d: PChar): integer; stdcall;

I have tried your declaration and got the following errors:

-warning C4518: '__declspec(dllimport ) ' : storage-class or type specifier(s) unexpected here; ignored

-warning C4502: 'linkage specification' requires use of keyword 'extern' and must precede all other specifiers

Linking...
-error LNK2001: unresolved external symbol _WinIVR_Dial
-fatal error LNK1120: 1 unresolved externals

One critical question. Don't I need to specify the DLL somewhere? eg the name of the DLL is MyDLL.dll.

Keith
0
keithcslAuthor Commented:
Opps. Sorry, the line

error LNK2001: unresolved external symbol _WinIVR_Dial

was meant to be:

error LNK2001: unresolved external symbol _MyFunc

I was playing with several DLLs and copied the wrong thing.

Keith
0
nietodCommented:
last question first (its the easiest)

>> Don't I need to specify the DLL somewhere?
Sort of, you need to specify the DLL's export library.  That is the .lib file produced when the DLL was created, not the DLL itself.

As to the other errors, they don't make sense.  Can you post the code you used including a few lines before and after this function's declaration.   (something nearby might be causing the problem.)
0
keithcslAuthor Commented:
nietod

thanks for the answer. my other problem was the linking of the DLL. i am now using explicit linking and it all works.

keith
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.