别人开发好的dll的com组件,如何在vc中注册使用.
对象文件名:HsCommX.Dll
本动态库为COM对象,使用前需要使用RegSvr32等命令注册, 如:RegSvr32 HsCommX.Dll命令。
请看我现在有VB和Delphi上对一个com对象使用,但是不知道VC下如何调用.
这是VB下的
Declare objComm As HsCommX//定义对象
objComm = CreateObject(‘HsCommX.Comm’)
objComm.Create //创建对象
这是DEPHI下的
var
test:Variant; //定义对象test
test := CreateOleObject( 'HsCommX.Comm '); //创建对象test
test.create;
请问VC中如何定义这个对象啊?
[解决办法]
你的组件具体输出什么接口我不清楚,给你个用#import 引入ado组件的例子参考一下
#import "c:\Program Files\Common Files\System\ADO\msado15.dll " \
no_namespace rename( "EOF ", "EndOfFile ")
#include <stdio.h>
// Note 1
inline void TESTHR( HRESULT _hr )
{ if FAILED(_hr) _com_issue_error(_hr); }
void main(void)
{
CoInitialize(NULL);
try
{
_RecordsetPtr pRs( "ADODB.Recordset ");
_ConnectionPtr pCn( "ADODB.Connection ");
_variant_t vtTableName( "authors "),
vtCriteria;
long ix[1];
SAFEARRAY *pSa = NULL;
pCn-> Open( "DSN=pubs;Integrated Security=SSPI;
Provider=MSDASQL; ", " ", " ",
adConnectUnspecified);
// Note 2, Note 3
pSa = SafeArrayCreateVector(VT_VARIANT, 1, 4);
if (!pSa) _com_issue_error(E_OUTOFMEMORY);
// Specify TABLE_NAME in the third array element (index of 2).
ix[0] = 2;
TESTHR(SafeArrayPutElement(pSa, ix, &vtTableName));
// There is no Variant constructor for a SafeArray, so manually set the
// type (SafeArray of Variant) and value (pointer to a SafeArray).
vtCriteria.vt = VT_ARRAY | VT_VARIANT;
vtCriteria.parray = pSa;
pRs = pCn-> OpenSchema(adSchemaColumns, vtCriteria, vtMissing);
long limit = pRs-> GetFields()-> Count;
for (long x = 0; x < limit; x++)
printf( "%d: %s\n ", x+1,
((char*) pRs-> GetFields()-> Item[x]-> Name));
// Note 4
pRs-> Close();
pCn-> Close();
}
catch (_com_error &e)
{
printf( "Error:\n ");
printf( "Code = %08lx\n ", e.Error());
printf( "Code meaning = %s\n ", (char*) e.ErrorMessage());
printf( "Source = %s\n ", (char*) e.Source());
printf( "Description = %s\n ", (char*) e.Description());
}
CoUninitialize();
}