×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Invocating DLL compiled with VisualC++ (VStudio98)

Invocating DLL compiled with VisualC++ (VStudio98)

Invocating DLL compiled with VisualC++ (VStudio98)

(OP)
Hi, people.
I want to run a function defined into a DLL from VB.
P.E., a simple stupyd example...

long sum (int s1, int s2);

-----
------ DLLmain developed by the C++'s DLL wizard itself
-----
long sum (int s1, int s2)
{
return (s1 + s2)
}

OK, I compile this and correctly declare in VB Module:

Declare Function sum Lib MyDLL (ByVal s1 as Integer, ByVal
s2 as Integer) As Long

but an error was found during the invocation in VB:

res = sum ( 1 + 1 )

something about this: the entry of the DLL couldn't be found

What this?!
THANX

RE: Invocating DLL compiled with VisualC++ (VStudio98)

Hi arlequin!

OK a couple of questions:
1) Your sum isn't going inside the DLLMain, is it? The DLLMain function is called by the OS when the DLL is first loaded. You can't/shouldn't call it yourself.

2) Did you preface your sum() function with "APIENTRY", so that it would be visible to outside callers? It should look like:

    int APIENTRY sum(int s1, int s2) {
        return (s1 + s2);
    }

You can check this my doing a quickview on the DLL (right click on file, choose "QuickView"). Look in the exports section for your function name. If the name is there, but it's mangled, then you need to export it as a "C" function, not a C++ function. Easiest way to do that is rename your source file from .cpp to .c and recompile and link.

Chip H.
PS. Don't forget to include exception handling in your DLL to handle overflow conditions, like when someone calls your function with 2,000,000 and 2,000,000, which would overflow the capacity of an int return.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close