请问c语言如何调用com组件?

firewangcool 2006-10-17 06:45:43
兄弟对c语言不是很熟悉,现在需要做一个和clear quest有关的项目;
clear quest提供了com组件,并且给了一些关于vb调用clear quest的com组件的api和例子,并且我已经用vb调用成功;
但是,我们的项目需要用c语言来实现这个com组件的调用,现在不知道该怎么实现?

vb能够调用的com组件c语言能调用吗?
提供一些vb调用的例句,谁能提示我用c语言如何来实现这些功能?
Set oSession = CreateObject("CLEARQUEST.SESSION")oSession.UserLogon "tms_insert", "tms_insert", "TMS", AD_PRIVATE_SESSION, ""
Set oEntity = oSession.BuildEntity("TMS_RWXX")
oEntity.setFieldValue "fatherdocunid", doc.UniversalID
oEntity.setFieldValue "FLD_RWMSH", doc.rw_ms(0)
oEntity.setFieldValue "FLD_JHGZL", doc.rw_name(0)

str1 = oEntity.Validate
If str1 <> "" Then
Msgbox "str1=" & str1
End If

oEntity.Commit
Set oEntity = Nothing
Set oSession = Nothing
...全文
719 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
firewangcool 2006-10-18
  • 打赏
  • 举报
回复
呵呵,这就打分结贴!
searingice 2006-10-18
  • 打赏
  • 举报
回复
别着急谢,结了帖先。
firewangcool 2006-10-18
  • 打赏
  • 举报
回复
真是谢谢各位啊!看来我还得找本com和c语言相关的书好好读读!
再次谢谢各位的回复!
飞哥 2006-10-17
  • 打赏
  • 举报
回复
两行是一行!
飞哥 2006-10-17
  • 打赏
  • 举报
回复
也可以这样访问
---------
这个是我写的
NtQuerySystemInformation = (long(__stdcall*)(DWORD, PVOID, DWORD, DWORD))
GetProcAddress( GetModuleHandle( "ntdll.dll" ),NtQuerySystemInformation"
);
飞哥 2006-10-17
  • 打赏
  • 举报
回复
◎◎simple test
========
◎◎
#include <stdio.h>

#include <windows.h>

typedef int(*lpAddFun)(int, int); //宏定义函数指针类型

int main(int argc, char *argv[])

{

HINSTANCE hDll; //DLL句柄

lpAddFun addFun; //函数指针

hDll = LoadLibrary("..\\Debug\\dllTest.dll");

if (hDll != NULL)

{

addFun = (lpAddFun)GetProcAddress(hDll, "add");

if (addFun != NULL)

{

int result = addFun(2, 3);

printf("%d", result);

}

FreeLibrary(hDll);

}

return 0;

}


shone_sun 2006-10-17
  • 打赏
  • 举报
回复
::CoInitializeEx(NULL, COINIT_MULTITHREADED);
IMessengerPtr Messager = NULL;

HRESULT hr = Messager.CreateInstance(__uuidof(Messenger));
::CoUninitialize();


MSNMessager->方法
phidix 2006-10-17
  • 打赏
  • 举报
回复
查COM相关函数,控件注册了以后注册表里有UUID和文件路径,忘了用什么函数了,随便找本COM原理的书就有。好像还要拿到接口的描述吧,.h文件或者IDL
飞哥 2006-10-17
  • 打赏
  • 举报
回复
使用Windows API函数LoadLibray和GetProcAddress
FARPROC GetProcAddress(
HMODULE hModule, // handle to DLL module
LPCSTR lpProcName // name of function
);
Parameters
hModule
Handle to the DLL module that contains the function. The LoadLibrary or GetModuleHandle function returns this handle.
lpProcName
Pointer to a null-terminated string containing the function name, or specifies the function's ordinal value. If this parameter is an ordinal value, it must be in the low-order word; the high-order word must be zero.

--------------------


firewangcool 2006-10-17
  • 打赏
  • 举报
回复
我查了一下LoadLibrary是载入dll到内存中,我的cq的dll文件已经写入注册表中了,我在vb中就可以直接使用这个语句Set oSession = CreateObject("CLEARQUEST.SESSION")dll中的方法入口,在c语言中如何获得这个入口?用HINSTANCE h = LoadLibrary("yourcom.dll");就可以吗?
飞哥 2006-10-17
  • 打赏
  • 举报
回复
不用客气
一起学习中!
firewangcool 2006-10-17
  • 打赏
  • 举报
回复
感谢wanfustudio(雁南飞:不慕虚名务潜修) 提示,谢谢
飞哥 2006-10-17
  • 打赏
  • 举报
回复
#include <windows.h>
#include <stdio.h>

void main()
{

HINSTANCE h = LoadLibrary("yourcom.dll");
}
firewangcool 2006-10-17
  • 打赏
  • 举报
回复
dll已经有了,我只会vb调用这个dll,不会c语言调用,所以请教一下大家,如何通过c语言写程序调用dll
飞哥 2006-10-17
  • 打赏
  • 举报
回复
COM编译成DLL
调DLL

69,371

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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