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 / C++ Libraries / December 2003

Tip: Looking for answers? Try searching our database.

Calling Win32 DLL from VB6 Function

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Joe Hoggood - 18 Nov 2003 19:14 GMT
Seems I can't call a Win32 DLL exported function from a VB6 function. I can
call it successfully from a VB6 Form_Load event. Strange. Any ideas? Here's
the exported C++.NET function and VB6 Function.

// Win32DLL.cpp : Defines the entry point for the DLL application.

#include "stdafx.h"

#include "Win32DLL.h"

BOOL APIENTRY DllMain(

HANDLE hModule,

DWORD ul_reason_for_call,

LPVOID lpReserved

)

{

switch (ul_reason_for_call)

{

case DLL_PROCESS_ATTACH:

case DLL_THREAD_ATTACH:

case DLL_THREAD_DETACH:

case DLL_PROCESS_DETACH:

break;

}

return TRUE;

}

// This is an example of an exported variable

// WIN32DLL_API int nWin32DLL = 0;

// This is an example of an exported function.

// WIN32DLL_API int fnWin32DLL(int varIn)

extern "C" __declspec(dllexport) int fnWin32DLL(int varIn)

{

int varOut;

varOut = varIn;

return 42 * varIn;

}

// This is the constructor of a class that has been exported. See Win32DLL.h
for the class definition

CWin32DLL::CWin32DLL()

{

return;

}

Private Sub cmdCompute_Click()
   Dim x As Long

   x = DoExternFunc(CInt(txtInputVarA.Text))
   'x = fnWin32DLL(CInt(txtInputVarA.Text))
   txtInputVarA.Text = CStr(x)
End Sub

'Set up global declarations and declare functions
Declare Function fnWin32DLL Lib
"C:\jhoggood\Applications\CommonC\BuildFiles\Win32DLL\Debug\Win32DLL.dll"
(ByVal varIn As Long) As Long

Public Function DoExternFunc(ByVal myInputVarA As Long) As Long
   DoExternFunc = fnWin32DLL(myInputVarA)
   'DoExternFunc = myInputVarA * 5
End Function
Michael Fitzpatrick - 12 Dec 2003 05:43 GMT
You probably need to declare the function as __stdcall. Usually the default
for C++ is to use __cdecl

This is how the stack frame is managed.

> Seems I can't call a Win32 DLL exported function from a VB6 function. I can
> call it successfully from a VB6 Form_Load event. Strange. Any ideas? Here's
[quoted text clipped - 86 lines]
>     'DoExternFunc = myInputVarA * 5
> End Function

Rate this thread:







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.