[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

5.4

C/C++ DLLs for use with VB in 32-bits

Asked by rpb in Windows Programming

Tags: winapi, __far, _export, dll

I have a bunch of DLLs with exported functions (basically it's an API) for use by other people using, for example, VB, or C/C++, or PowerBuilder, etc.  The DLLs are written in C/C++, and the exported functions are just C functions.  So, for example, I might have some functions like these:

   WORD  MyAPIInit()
   short MyAPIDoSomething(LPCSTR buff, short bufflen)
   BOOL  MyAPIShutDown(WORD handle)

etc., exported from the DLL.

In 16-bits, I had these declared using the WINAPI and EXPORT macros, which are equivalent to __far __pascal and __export respectively.  When I built my DLL, I then got these functions exported, and the __pascal bit meant that

   (a) they were callable from VB, etc., with left-to-right parameter passing, and

   (b) the names of the exported functions got made into uppercase, since the pascal calling convention is case-insensitive.

Note that I also had extern "C" in front of the declarations and definitions, and did *not* put any of the functions in the def file, since the EXPORT macro has the same effect and saves me updating both the functions and the def file all the time.

All worked fine up until I moved to 32-bits.  Now I have a bunch of 32-bit DLLs, and so instead of my previous:

   extern "C" BOOL WINAPI EXPORT MyAPIShutDown(WORD handle)

I now have

   extern "C" EXPORT BOOL WINAPI MyAPIShutDown(WORD handle)

because 32-bits needs the EXPORT in a different place.

However, WINAPI now means, not __pascal, but __stdcall.  And from reading the VB help (what little there is on this topic) I find that VB requires DLL functions to use the __stdcall calling convention.

Unfortunately, when I build my DLL, all the exported functions get name decorated, with a preceding underscore, and an "@n" tacked on the end, where n is the number of bytes the parameters take up.  Standard Windows DLLs (which can be called from VB and so presumably use the __stdcall convention) are not so decorated, so how do I get rid of this decoration so that people can use my 32-bit DLL as they did the 16-bit one?  On the odd occasions I have got the functions to work (by using the Alias keyword in VB), I get "Bad DLL Calling Convention" followed by a VB crash.  It is possible that I have not specified the function correctly in VB for this, or it is possible that my calling convention is incorrect.

What this boils down to is how should I declare and define an exported function in a DLL so that it can be used by VB and C, and is exported with a particular name (rather than a decorated one) in 32-bits compared to 16-bits.

Any help will be much appreciated.
[+][-]08/27/97 07:16 AM, ID: 1404905Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zone: Windows Programming
Tags: winapi, __far, _export, dll
Sign Up Now!
Solution Provided By: kfe
Participating Experts: 2
Solution Grade: C
 
[+][-]08/27/97 02:02 AM, ID: 1404899Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08/27/97 04:49 AM, ID: 1404900Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08/27/97 04:51 AM, ID: 1404901Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08/27/97 05:26 AM, ID: 1404902Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08/27/97 06:50 AM, ID: 1404903Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08/27/97 06:54 AM, ID: 1404904Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08/27/97 11:26 AM, ID: 1404906Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08/28/97 03:33 AM, ID: 1404907Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091118-EE-VQP-93