急急急,跪求。。在c++ builder中ocx控件导入后,怎么使用。

ljw02095513 2012-09-04 08:32:42
我选择“组件”---》“导入activex控件”——》添加自己的ocx---->然后选择创建单元。
然后新建立了一个console程序,在这个程序里面,包含了控件生成的头文件,可我怎么调用控件里的方法啊。
...全文
139 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
ljw02095513 2012-09-04
  • 打赏
  • 举报
回复
上面出错是因为没调用CoInitialize(NULL),调用下就好了。感谢您的回复。确实是参数传错了。运行不了。
缘中人 2012-09-04
  • 打赏
  • 举报
回复
是尚未调用"Coinitialize"
加入头文件 #include <objbase.h>
//CoInitialize()在头文件objbase.h中定义


long pRet;
WideString strVersion;
CoInitialize(NULL);
TPrntInterface *a= new TPrntInterface(Application);
a->GetVersion(&strVersion, &pRet);
CoUninitialize();


缘中人 2012-09-04
  • 打赏
  • 举报
回复
没看完,strVersion这个不能这样用啊
你可以

WideString str=L""; //或者BSTR str;
a->GetVersion(&strVersion, &pRet);
ljw02095513 2012-09-04
  • 打赏
  • 举报
回复
#pragma hdrstop
#include "PRNTINTERFACELib_OCX.h"

我写了个控制台程序测试。但是运行报错。弹出个对话框来,说是尚未调用"Coinitialize"
//---------------------------------------------------------------------------

#pragma argsused
int main(int argc, char* argv[])
{
long pRet;
wchar_t **strVersion;
TPrntInterface *a= new TPrntInterface(Application);
a->GetVersion(strVersion, &pRet);
return 0;
}
ljw02095513 2012-09-04
  • 打赏
  • 举报
回复
最好列下代码,谢谢各位了!
ljw02095513 2012-09-04
  • 打赏
  • 举报
回复
非常感谢您的回复。c++ builder我算是菜鸟级别,我试过new 一个实例,但是老是报错,说是我的构造函数的参数不对。我把生成的头文件给您列出来,能帮我看下怎么调用里面的 GetCurInv(BSTR* strData, long* pRet);






#ifndef PRNTINTERFACELib_OCXH
#define PRNTINTERFACELib_OCXH

#pragma option push -b -w-inl

#include <olectrls.hpp>
#include <utilcls.h>
#if !defined(__UTILCLS_H_VERSION) || (__UTILCLS_H_VERSION < 0x0600)
#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(_NO_VCL)
#include <stdvcl.hpp>
#endif // _NO_VCL
#include <ocxproxy.h>

#include "PRNTINTERFACELib_TLB.h"
namespace Prntinterfacelib_tlb
{
class PACKAGE TPrntInterface : public TOleControl
{
OVERLOADED_PROP_METHODS;
static TNoParam OptParam;
static GUID DEF_CTL_INTF;
_DPrntInterfaceDisp m_OCXIntf;
static TControlData CControlData;
static GUID CTL_DEF_INTF;
_DPrntInterfaceDisp __fastcall GetDefaultInterface();
_DPrntInterfaceDisp __fastcall GetControlInterface()
{ return GetDefaultInterface(); }

protected:
void __fastcall CreateControl ();
void __fastcall InitControlData();

public:
virtual __fastcall TPrntInterface(TComponent* AOwner) : TOleControl(AOwner)
{};
virtual __fastcall TPrntInterface(HWND Parent) : TOleControl(Parent)
{};
// OCX methods
//
long __fastcall GetCurInv(BSTR* strData, long* pRet);
long __fastcall GetPrntReturnData(BSTR* strData, long* pRet);
long __fastcall GetVersion(BSTR* strVersion, long* pRet);
long __fastcall PrntInv(BSTR strPrntData, long* pRet);
long __fastcall TestPrnt(long pRet);
long __fastcall GetErrInf(BSTR* pBstr);
long __fastcall GetInterfaceState(void);
long __fastcall PrntInv_GetInvInf(BSTR strPrntData, BSTR* strReInvCode,
BSTR* strReInvNO);
long __fastcall TestPrntRe(void);
long __fastcall PreviewInv(BSTR* strPrntData);
long __fastcall TestPreviewInv(void);
void __fastcall AboutBox(void);

// OCX properties
//
__property _DPrntInterfaceDisp ControlInterface={ read=GetDefaultInterface };

// Published properties
//
__published:

// Standard/Extended properties
//
__property TabStop;
__property Align;
__property DragCursor;
__property DragMode;
__property ParentShowHint;
__property PopupMenu;
__property ShowHint;
__property TabOrder;
__property Visible;
__property OnDragDrop;
__property OnDragOver;
__property OnEndDrag;
__property OnEnter;
__property OnExit;
__property OnStartDrag;

// OCX properties
//

// OCX Events
//
};
typedef TPrntInterface TPrntInterfaceProxy;

}; // namespace Prntinterfacelib_tlb

#if !defined(NO_IMPLICIT_NAMESPACE_USE)
using namespace Prntinterfacelib_tlb;
#endif

#pragma option pop

#endif // PRNTINTERFACELib_OCXH
dataxdata 2012-09-04
  • 打赏
  • 举报
回复
要new一个控件的实例,然后再使用里面的方法

703

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder ActiveX/COM/DCOM
社区管理员
  • ActiveX/COM/DCOM社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧