Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / March 2004

Tip: Looking for answers? Try searching our database.

Bad DLL Calling Cinvention

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
S.N. Yang - 30 Mar 2004 09:11 GMT
I use the C++.NET to write a dll and call this dll using VB6.

VC++ Code

#include "stdafx.h
BOOL APIENTRY DllMain( HANDLE hModule,
                      DWORD  ul_reason_for_call,
                      LPVOID lpReserve
                   

   return TRUE

extern "C" __declspec(dllexport) int SPS_Add ( int i1, int i2

    int  sum

    sum = i1 + i2
    return (sum)

VB Code

Sub Mai
   Declare Function SPS_Add Lib "SPS.dll" (ByVal i1 As Integer, ByVal i2 As Integer) As Intege
 
 Dim a1 As Integer, a2 As Integer, sum As Intege
 Dim temp1 As Strin

 a1 =
 a2 =

 sum = SPS_Add(a1, a2
 temp1 = a1 & " + " & a2 & " = " & su
 MsgBox temp
End Su

I run the VB and get an error: "Bad DLL Calling Convention.".    What is wrong

S.N. Yan
03/30/2004
Mattias Sj?gren - 30 Mar 2004 15:36 GMT
>I run the VB and get an error: "Bad DLL Calling Convention.".    What is wrong?

Your exported function must use the stdcall calling convention.

extern "C" __declspec(dllexport) int __stdcall SPS_Add ( int i1, int
i2 )

Oh, and in VB6 Integer is only 16 bits, so you should use Longs in the
Declare statement.

Mattias

Signature

Mattias Sjögren [MVP]  mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.