有沒有相關的例子,謝謝!
uj5u.com熱心網友回復:
和呼叫其它DLL一樣呼叫uj5u.com熱心網友回復:
資料很多的,http://wenku.baidu.com/link?url=mU_hWa7g7ZZ8KeHmCK_cFNFoa_jKiAhG6g0_c6VkKquvwynnMFiUeo_HK2vYtBovx4I3TDejdsxGb7FW6cTlWDMVPfb_Z5OZj_oRkEfASGu
uj5u.com熱心網友回復:
BCB怎么使用VB寫的Activex DLL? 是這樣的:我想把操作word的代碼用VB來撰寫,生成dll,然后通過BCB來呼叫,我想通過“Import Component”來加載,怎么弄呀?uj5u.com熱心網友回復:
可視化的部件直接寫成OCX吧uj5u.com熱心網友回復:
我是這樣操作的:1.在VB中生成dll

2.在BCB中參考

3.在BCB中加入
.h中
#include "vbmytestdll_TLB.cpp"
.cpp中
void __fastcall TForm1::Button1Click(TObject *Sender)
{
mytestdll *a; //mytestdll是VB中自定義的類名
this->Caption=a->dlltest1();
a->dk();
}
可以編繹,但點按鈕就出錯,請高手指導,我BCB還不是很熟悉,謝謝!
uj5u.com熱心網友回復:
我用Delphi可以呼叫了,代碼如下:var
aa:Comytestdll;
a:mytestdll;
begin
a:=aa.Create;
ShowMessage(a.dlltest1);
end;
但換成BCB卻有問題:
Comytestdll *aa;
mytestdll *a;
a=aa->Create();
ShowMessage(a->dlltest1());
編繹沒有問題,但一運行這段程式卻出現“access violation at address 769aefb3 in module 'ole32.dll“”錯誤,是怎么回事呀?
uj5u.com熱心網友回復:
mytestdll *a = new Comytestdll;ShowMessage(a->dlltest1());
uj5u.com熱心網友回復:
妖哥:我用mytestdll *a = new Comytestdll;編繹時出現如下錯誤:
[BCC32 Error] Unit1.cpp(21): E2034 Cannot convert 'Comytestdll *' to '_mytestdll *'
是哪里有問題呀?
uj5u.com熱心網友回復:
你這個 Comytestdll 和 mytestdll 分別是什么型別?uj5u.com熱心網友回復:
妖哥,麻煩您看一下吧,這個是VB的dll創建的.H檔案#ifndef vbmytestdll_TLBH
#define vbmytestdll_TLBH
#pragma option push -b -a4 -w-inl
#if !defined(__UTILCLS_H)
#include <utilcls.h>
#endif
#if !defined(__UTILCLS_H_VERSION) || (__UTILCLS_H_VERSION < 0x0700)
//
// The code generated by the TLIBIMP utility or the Import|TypeLibrary
// and Import|ActiveX feature of C++Builder rely on specific versions of
// the header file UTILCLS.H found in the INCLUDE\VCL directory. If an
// older version of the file is detected, you probably need an update/patch.
//
#error "This file requires a newer version of the header UTILCLS.H" \
"You need to apply an update/patch to your copy of C++Builder"
#endif
#include <olectl.h>
#include <ocidl.h>
#if defined(USING_ATLVCL) || defined(USING_ATL)
#if !defined(__TLB_NO_EVENT_WRAPPERS)
#include <atl/atlmod.h>
#endif
#endif
// *********************************************************************//
// Forward reference of some VCL types (to avoid including STDVCL.HPP)
// *********************************************************************//
namespace Stdvcl {class IStrings; class IStringsDisp;}
using namespace Stdvcl;
typedef TComInterface<IStrings> IStringsPtr;
typedef TComInterface<IStringsDisp> IStringsDispPtr;
namespace Vbmytestdll_tlb
{
// *********************************************************************//
// HelpString:
// Version: 1.0
// *********************************************************************//
// *********************************************************************//
// GUIDS declared in the TypeLibrary. Following prefixes are used:
// Type Libraries : LIBID_xxxx
// CoClasses : CLSID_xxxx
// DISPInterfaces : DIID_xxxx
// Non-DISP interfaces: IID_xxxx
// *********************************************************************//
extern __declspec (package) const GUID LIBID_vbmytestdll;
extern __declspec (package) const GUID IID__mytestdll;
extern __declspec (package) const GUID CLSID_mytestdll;
// *********************************************************************//
// Forward declaration of types defined in TypeLibrary
// *********************************************************************//
interface DECLSPEC_UUID("{26EB54BE-0B13-45B6-AF88-9DD5545DD65F}") _mytestdll;
typedef TComInterface<_mytestdll, &IID__mytestdll> _mytestdllPtr;
// *********************************************************************//
// Declaration of CoClasses defined in Type Library
// (NOTE: Here we map each CoClass to its Default Interface)
//
// The LIBID_OF_ macro(s) map a LIBID_OF_CoClassName to the GUID of this
// TypeLibrary. It simplifies the updating of macros when CoClass name
// change.
// *********************************************************************//
typedef _mytestdll mytestdll;
typedef _mytestdllPtr mytestdllPtr;
#define LIBID_OF_mytestdll (&LIBID_vbmytestdll)
// *********************************************************************//
// Interface: _mytestdll
// Flags: (4560) Hidden Dual NonExtensible OleAutomation Dispatchable
// GUID: {26EB54BE-0B13-45B6-AF88-9DD5545DD65F}
// *********************************************************************//
interface _mytestdll : public IDispatch
{
public:
virtual HRESULT STDMETHODCALLTYPE dk(void) = 0; // [1610809344]
virtual HRESULT STDMETHODCALLTYPE dlltest1(BSTR* Param1/*[out,retval]*/) = 0; // [1610809345]
#if !defined(__TLB_NO_INTERFACE_WRAPPERS)
BSTR __fastcall dlltest1(void)
{
BSTR Param1 = 0;
OLECHECK(this->dlltest1((BSTR*)&Param1));
return Param1;
}
#endif // __TLB_NO_INTERFACE_WRAPPERS
};
#if !defined(__TLB_NO_INTERFACE_WRAPPERS)
// *********************************************************************//
// SmartIntf: TCOM_mytestdll
// Interface: _mytestdll
// *********************************************************************//
template <class T /* _mytestdll */ >
class TCOM_mytestdllT : public TComInterface<_mytestdll>, public TComInterfaceBase<IUnknown>
{
public:
TCOM_mytestdllT() {}
TCOM_mytestdllT(_mytestdll *intf, bool addRef = false) : TComInterface<_mytestdll>(intf, addRef) {}
TCOM_mytestdllT(const TCOM_mytestdllT& src) : TComInterface<_mytestdll>(src) {}
TCOM_mytestdllT& operator=(const TCOM_mytestdllT& src) { Bind(src, true); return *this;}
HRESULT __fastcall dk(void);
HRESULT __fastcall dlltest1(BSTR* Param1/*[out,retval]*/);
BSTR __fastcall dlltest1(void);
};
typedef TCOM_mytestdllT<_mytestdll> TCOM_mytestdll;
// *********************************************************************//
// DispIntf: _mytestdll
// Flags: (4560) Hidden Dual NonExtensible OleAutomation Dispatchable
// GUID: {26EB54BE-0B13-45B6-AF88-9DD5545DD65F}
// *********************************************************************//
template<class T>
class _mytestdllDispT : public TAutoDriver<_mytestdll>
{
public:
_mytestdllDispT(){}
_mytestdllDispT(_mytestdll *pintf)
{
TAutoDriver<_mytestdll>::Bind(pintf, false);
}
_mytestdllDispT(_mytestdllPtr pintf)
{
TAutoDriver<_mytestdll>::Bind(pintf, true);
}
_mytestdllDispT& operator=(_mytestdll *pintf)
{
TAutoDriver<_mytestdll>::Bind(pintf, false);
return *this;
}
_mytestdllDispT& operator=(_mytestdllPtr pintf)
{
TAutoDriver<_mytestdll>::Bind(pintf, true);
return *this;
}
HRESULT BindDefault()
{
return OLECHECK(Bind(CLSID_mytestdll));
}
HRESULT BindRunning()
{
return BindToActive(CLSID_mytestdll);
}
HRESULT __fastcall dk();
HRESULT __fastcall dlltest1(BSTR* Param1/*[out,retval]*/);
BSTR __fastcall dlltest1(void);
};
typedef _mytestdllDispT<_mytestdll> _mytestdllDisp;
// *********************************************************************//
// SmartIntf: TCOM_mytestdll
// Interface: _mytestdll
// *********************************************************************//
template <class T> HRESULT __fastcall
TCOM_mytestdllT<T>::dk(void)
{
return (*this)->dk();
}
template <class T> HRESULT __fastcall
TCOM_mytestdllT<T>::dlltest1(BSTR* Param1/*[out,retval]*/)
{
return (*this)->dlltest1(Param1);
}
template <class T> BSTR __fastcall
TCOM_mytestdllT<T>::dlltest1(void)
{
BSTR Param1 = 0;
OLECHECK(this->dlltest1((BSTR*)&Param1));
return Param1;
}
// *********************************************************************//
// DispIntf: _mytestdll
// Flags: (4560) Hidden Dual NonExtensible OleAutomation Dispatchable
// GUID: {26EB54BE-0B13-45B6-AF88-9DD5545DD65F}
// *********************************************************************//
template <class T> HRESULT __fastcall
_mytestdllDispT<T>::dk()
{
_TDispID _dispid(*this, OLETEXT("dk"), DISPID(1610809344));
return OleFunction(_dispid);
}
template <class T> HRESULT __fastcall
_mytestdllDispT<T>::dlltest1(BSTR* Param1/*[out,retval]*/)
{
_TDispID _dispid(*this, OLETEXT("dlltest1"), DISPID(1610809345));
TAutoArgs<0> _args;
return OutRetValSetterPtr(Param1 /*[VT_BSTR:1]*/, _args, OleFunction(_dispid, _args));
}
template <class T> BSTR __fastcall
_mytestdllDispT<T>::dlltest1(void)
{
BSTR Param1;
this->dlltest1((BSTR*)&Param1);
return Param1;
}
// *********************************************************************//
// The following typedefs expose classes (named CoCoClassName) that
// provide static Create() and CreateRemote(LPWSTR machineName) methods
// for creating an instance of an exposed object. These functions can
// be used by client wishing to automate CoClasses exposed by this
// typelibrary.
// *********************************************************************//
// *********************************************************************//
// COCLASS DEFAULT INTERFACE CREATOR
// CoClass : mytestdll
// Interface: TCOM_mytestdll
// *********************************************************************//
typedef TCoClassCreatorT<TCOM_mytestdll, _mytestdll, &CLSID_mytestdll, &IID__mytestdll> Comytestdll;
#endif // __TLB_NO_INTERFACE_WRAPPERS
}; // namespace Vbmytestdll_tlb
#if !defined(NO_IMPLICIT_NAMESPACE_USE)
using namespace Vbmytestdll_tlb;
#endif
#pragma option pop
#endif // vbmytestdll_TLBH
uj5u.com熱心網友回復:
Delphi下測驗通過:var
aa:Comytestdll;
a:mytestdll;
begin
a:=aa.Create;
ShowMessage(a.dlltest1);
end;
但BCB我卻弄不來。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/118600.html
標籤:基礎類
