ok....i'm trying to build a dll file in c++. I'm just a beginner here and i want to make functions in c++, incorporate them into a .dll file and then use those functions in vb via a .dll file.
#ifndef __AFXWIN_H__
#error include 'stdafx.h' before including this file for PCH
#endif
#include "resource.h" // main symbols
/////////////////////////////////////////////////////////////////////////////
// CTestApp
// See test.cpp for the implementation of this class
//
class CTestApp : public CWinApp
{
public:
CTestApp();
char* hi();
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CTestApp)
//}}AFX_VIRTUAL
//{{AFX_MSG(CTestApp)
// NOTE - the ClassWizard will add and remove member functions here.
// DO NOT EDIT what you see in these blocks of generated code !
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
//
// Note!
//
// If this DLL is dynamically linked against the MFC
// DLLs, any functions exported from this DLL which
// call into MFC must have the AFX_MANAGE_STATE macro
// added at the very beginning of the function.
//
// For example:
//
// extern "C" BOOL PASCAL EXPORT ExportedFunction()
// {
// AFX_MANAGE_STATE(AfxGetStaticModuleState());
// // normal function body here
// }
//
// It is very important that this macro appear in each
// function, prior to any calls into MFC. This means that
// it must appear as the first statement within the
// function, even before any object variable declarations
// as their constructors may generate calls into the MFC
// DLL.
//
// Please see MFC Technical Notes 33 and 58 for additional
// details.
//
BEGIN_MESSAGE_MAP(CTestApp, CWinApp)
//{{AFX_MSG_MAP(CTestApp)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTestApp construction
CTestApp::CTestApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}
char* CTestApp::hi()
{
return "Hello";
}
/////////////////////////////////////////////////////////////////////////////
// The one and only CTestApp object
now all this code compiles fine and creates the dll file but when i want to use it in visual basic I create a module and add the following line of code to it.
Public Declare Function Test Lib "test.dll" Alias "hi" () As String
then in my main form i have
Private Sub Form_Load()
MsgBox Test
End Sub
when i run the program it gives me this error:
Run-time error '453':
Can't find DLL entry point hi in test.dll
The main problem here is that you've created an MFC DLL, not a proper DLL. You need to select project type "Win32 DLL". This won't create any source files for you, allowing you to create your own functions. I've attached an example.
There are two things to watch out for:
1. All exported functions must have the calling convention "__stdcall", as seen in the source file.
2. The exported functions must be named in the .DEF file
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You". -- Linus Torvalds