VB调用DLL出错我的VB代码如下
Private declare Function CreateInstance Lib "TestVb.dll" As Object
Dim App As Object
Dim count As longprivate Sub Command1_clikc()
set App = CreateInstance()
count = App.getCount()
End Sub我的Dll代码如下
TestVb.def文件内容TestVb.def - defines the exports for TestVb.dllLIBRARY TestVb
DESCRIPTION 'A C++ dll that can be called from VB'EXPORTS
CreateInstanceTestVb.h文件内容
class CTestVb {
public:
CTestVb(void);
// TODO: add your methods here.
};class CApplication
{
public:
CApplication(void) ;
int getCounter();
};extern int nTestVb;int fnTestVb(void);
CApplication* __stdcall CreateInstance();
TestVb.cpp文件内容#include "stdafx.h"
#include "TestVb.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
int nTestVb=0;// This is an example of an exported function.
int fnTestVb(void)
{
return 42;
}// This is the constructor of a class that has been exported.
// see TestVb.h for the class definition
CTestVb::CTestVb()
{
return;
}CApplication::CApplication()
{}int CApplication::getCounter()
{
return 10 ;
}CApplication* __stdcall CreateInstance()
{
CApplication *app = new CApplication ;
return app ;
}
但我在VB里一点Button的按钮就错了,如果CreateInstance没有返回对象,我在VB是可以调用的,请问有返回对象时并调用对象的方法如这里getCount()应该怎么写,谢谢!
Private declare Function CreateInstance Lib "TestVb.dll" As Object
Dim App As Object
Dim count As longprivate Sub Command1_clikc()
set App = CreateInstance()
count = App.getCount()
End Sub我的Dll代码如下
TestVb.def文件内容TestVb.def - defines the exports for TestVb.dllLIBRARY TestVb
DESCRIPTION 'A C++ dll that can be called from VB'EXPORTS
CreateInstanceTestVb.h文件内容
class CTestVb {
public:
CTestVb(void);
// TODO: add your methods here.
};class CApplication
{
public:
CApplication(void) ;
int getCounter();
};extern int nTestVb;int fnTestVb(void);
CApplication* __stdcall CreateInstance();
TestVb.cpp文件内容#include "stdafx.h"
#include "TestVb.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
int nTestVb=0;// This is an example of an exported function.
int fnTestVb(void)
{
return 42;
}// This is the constructor of a class that has been exported.
// see TestVb.h for the class definition
CTestVb::CTestVb()
{
return;
}CApplication::CApplication()
{}int CApplication::getCounter()
{
return 10 ;
}CApplication* __stdcall CreateInstance()
{
CApplication *app = new CApplication ;
return app ;
}
但我在VB里一点Button的按钮就错了,如果CreateInstance没有返回对象,我在VB是可以调用的,请问有返回对象时并调用对象的方法如这里getCount()应该怎么写,谢谢!
谢谢!
这样是可以,但我要调用getCount方法又要如何做了。
vc的对象导出以后vb可以直接使用?怀疑
Set VBExcel=CreateObject ("Excel.Application")
X=VBExcel. Evaluate ("3+5*(cos (1/log (99. 9)))")