召唤VC大神,在VC中调用VFP编译的COM组件问题

elongwang1 2014-05-05 10:00:26
如何在vc中调用vfp写的Com组件或者DLL。
vfp比较懂了,vc还在初级学习中,最好能有VC6+vfp9的实例.
trickglom大神的《进来吆喝下:VFP写的DLL能够被VC调用》没看懂;
十豆三大神说的也不是很详细,我的VC是本初级书,没有COM方面的知识。
如果上边两位大神也碰巧看见了,麻烦讲得详细一点。
...全文
232 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
elongwang1 2014-05-08
  • 打赏
  • 举报
回复
这种方法只是实在没有办法了才用。 我用VFP做过IE的网页挂,同时开10多个程序,但是只要有1个崩溃了,其余的一起都无法运行,因为崩溃那个直接让CPU达到100%。 我还做个IE的网页挂,但是IE要弹出对话框进行数字证书的确认,因为vfp没有多线程,只能再写个vfp的程序,专门点击。 即使按照上上文的对文件进行监控实现了无缝对接,始终操作磁盘文件比操作内存要慢得多,特别是在对大量数据进行反复运算时,调用磁盘文件就比较费时。 比如我们要读取1个G的数据时,vfp读取磁盘文件的时间就远远高于VC将这1个G的数组地址传给VFP
elongwang1 2014-05-08
  • 打赏
  • 举报
回复
上面大串鸟文真心看不懂。不过我知道在内存里读数据肯定比读磁盘文件快。
赵4老师 2014-05-08
  • 打赏
  • 举报
回复
不要小看操作系统文件管理的智商!
赵4老师 2014-05-08
  • 打赏
  • 举报
回复
效率慢不慢,耗不耗资源,不是凭你的主观想象,而是用profiler和资源管理器实际观察得到的结果来证明的。 不要迷信书、考题、老师、回帖; 要迷信CPU、编译器、调试器、运行结果。 并请结合“盲人摸太阳”和“驾船出海时一定只带一个指南针。”加以理解。 任何理论、权威、传说、真理、标准、解释、想象、知识……都比不上摆在眼前的事实! 有人说一套做一套,你相信他说的还是相信他做的? 其实严格来说这个世界上古往今来所有人都是说一套做一套,不是吗? 不要写连自己也预测不了结果的代码!
赵4老师 2014-05-08
  • 打赏
  • 举报
回复
引用 12 楼 elongwang1 的回复:
[quote=引用 10 楼 zhao4zhong1 的回复:] 效率慢不慢,耗不耗资源,不是凭你的主观想象,而是用profiler和资源管理器实际观察得到的结果来证明的。 不要迷信书、考题、老师、回帖; 要迷信CPU、编译器、调试器、运行结果。 并请结合“盲人摸太阳”和“驾船出海时一定只带一个指南针。”加以理解。 任何理论、权威、传说、真理、标准、解释、想象、知识……都比不上摆在眼前的事实! 有人说一套做一套,你相信他说的还是相信他做的? 其实严格来说这个世界上古往今来所有人都是说一套做一套,不是吗? 不要写连自己也预测不了结果的代码!
你这种需要VC和VFP随时监控磁盘文件,如果不设定个定时器,就要挂个钩子,不然一直监控的话,必须是双核以上的CPu才能胜任(而且有2核一定是100%),而且磁盘文件的读写效率本来就低,唯一的优点就是通吃,什么情况都能应付。用DLL,直接共享内存空间,而且VC可以开多线程,效率肯定DLL快三,缺点就是需要两种语言的相互配合。[/quote] ReadDirectoryChangesW The ReadDirectoryChangesW function returns information describing the changes occurring within a directory. BOOL ReadDirectoryChangesW( HANDLE hDirectory, // handle to the directory to be watched LPVOID lpBuffer, // pointer to the buffer to receive the read // results DWORD nBufferLength, // length of lpBuffer BOOL bWatchSubtree, // flag for monitoring directory or // directory tree DWORD dwNotifyFilter, // filter conditions to watch for LPDWORD lpBytesReturned, // number of bytes returned LPOVERLAPPED lpOverlapped, // pointer to structure needed for // overlapped I/O LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine // pointer to completion routine ); Parameters hDirectory Handle to the directory to be watched. This directory must be opened with the FILE_LIST_DIRECTORY access right. lpBuffer Specifies the address of the formatted buffer in which the read results are to be returned. The structure of this buffer is defined by the FILE_NOTIFY_INFORMATION structure. This buffer is filled either synchronously or asynchronously, depending on how the directory is opened and what value is given to the lpOverlapped parameter. For more information, see the Remarks section. nBufferLength Specifies the length of the buffer pointed to by the lpBuffer parameter. bWatchSubtree Specifies whether the ReadDirectoryChangesW function will monitor the directory or the directory tree. If TRUE is specified, the function monitors the directory tree rooted at the specified directory. If FALSE is specified, the function monitors only the directory specified by the hDirectory parameter. dwNotifyFilter Specifies filter criteria the function checks to determine if the wait operation has completed. This parameter can be one or more of the following values: Value Meaning FILE_NOTIFY_CHANGE_FILE_NAME Any filename change in the watched directory or subtree causes a change notification wait operation to return. Changes include renaming, creating, or deleting a file. FILE_NOTIFY_CHANGE_DIR_NAME Any directory-name change in the watched directory or subtree causes a change notification wait operation to return. Changes include creating or deleting a directory. FILE_NOTIFY_CHANGE_ATTRIBUTES Any attribute change in the watched directory or subtree causes a change notification wait operation to return. FILE_NOTIFY_CHANGE_SIZE Any file-size change in the watched directory or subtree causes a change notification wait operation to return. The operating system detects a change in file size only when the file is written to the disk. For operating systems that use extensive caching, detection occurs only when the cache is sufficiently flushed. FILE_NOTIFY_CHANGE_LAST_WRITE Any change to the last write-time of files in the watched directory or subtree causes a change notification wait operation to return. The operating system detects a change to the last write-time only when the file is written to the disk. For operating systems that use extensive caching, detection occurs only when the cache is sufficiently flushed. FILE_NOTIFY_CHANGE_LAST_ACCESS Any change to the last access time of files in the watched directory or subtree causes a change notification wait operation to return. FILE_NOTIFY_CHANGE_CREATION Any change to the creation time of files in the watched directory or subtree causes a change notification wait operation to return. FILE_NOTIFY_CHANGE_SECURITY Any security-descriptor change in the watched directory or subtree causes a change notification wait operation to return. lpBytesReturned For synchronous calls, this parameter specifies the number of bytes transferred into the lpBuffer parameter. For asynchronous calls, this parameter is undefined. You must use an asynchronous notification technique to retrieve the number of bytes transferred. lpOverlapped Pointer to an OVERLAPPED structure that supplies data to be used during asynchronous operation. Otherwise, this value is NULL. The Offset and OffsetHigh members of this structure are not used. lpCompletionRoutine Pointer to a completion routine to be called when the operation has been completed or canceled and the calling thread is in an alertable wait state. For more information about this completion routine, see FileIOCompletionRoutine. Return Values If the function succeeds, the return value is nonzero. For synchronous calls, this means that the operation succeeded. For asynchronous calls, this indicates that the operation was successfully queued. If the function fails, the return value is zero. To get extended error information, call GetLastError. Remarks To obtain a handle to a directory, use the CreateFile function with FILE_FLAG_BACKUP_SEMANTICS as follows: hDir = CreateFile( DirName, // pointer to the file name FILE_LIST_DIRECTORY, // access (read-write) mode FILE_SHARE_READ|FILE_SHARE_DELETE, // share mode NULL, // security descriptor OPEN_EXISTING, // how to create FILE_FLAG_BACKUP_SEMANTICS, // file attributes NULL // file with attributes to copy ); A call to ReadDirectoryChangesW can be completed synchronously or asynchronously. To specify asynchronous completion, open the directory with CreateFile as shown above, but additionally specify the FILE_FLAG_OVERLAPPED attribute in the dwFlagsAndAttributes parameter. Then specify an OVERLAPPED structure when you call ReadDirectoryChangesW. Upon successful synchronous completion, the lpBuffer parameter is a formatted buffer and the number of bytes written to the buffer is available in lpBytesReturned. If the number of bytes transferred is zero, the buffer was too small to provide detailed information on all the changes that occurred in the directory or subtree. In this case, you should compute the changes by enumerating the directory or subtree. For asynchronous completion, you can receive notification in one of three ways: Using the GetOverlappedResult function. To receive notification through GetOverlappedResult, do not specify a completion routine in the lpCompletionRoutine parameter. Be sure to set the hEvent member of the OVERLAPPED structure to a unique event. Using the GetQueuedCompletionStatus function. To receive notification through GetQueuedCompletionStatus, do not specify a completion routine in lpCompletionRoutine. Associate the directory handle hDirectory with a completion port by calling the CreateIoCompletionPort function. Using a completion routine. To receive notification through a completion routine, do not associate the directory with a completion port. Specify a completion routine in lpCompletionRoutine. This routine is called whenever the operation has been completed or canceled while the thread is in an alertable wait state. The hEvent member of the OVERLAPPED structure is not used by the system, so you can use it yourself. QuickInfo Windows NT: Requires version 4.0 or later. Windows: Unsupported. Windows CE: Unsupported. Header: Declared in winbase.h. Import Library: Use kernel32.lib. See Also File I/O Overview, File Functions, CreateFile, CreateIoCompletionPort, FILE_NOTIFY_INFORMATION, FileIOCompletionRoutine, GetOverlappedResult, GetQueuedCompletionStatus, OVERLAPPED
elongwang1 2014-05-08
  • 打赏
  • 举报
回复
引用 8 楼 zhao4zhong1 的回复:
VC将请求数据写到文件a.txt,写完后改名为aa.txt VFP发现aa.txt存在时,读取其内容,调用相应功能,将结果写到文件b.txt,写完后删除aa.txt,改名为bb.txt VC发现bb.txt存在时,读取其内容,读完后删除bb.txt 以上VC可以替换为A(任何开发语言或开发环境),VFP可以替换为B(任何与A不同的开发语言或开发环境) 除非A或B不支持文件读写和文件更名。 但是谁又能举出不支持文件读写和文件更名的开发语言或开发环境呢?
比如说这段功能就可以改为: VC把请求数据放到内存,调用vfp的DLL,vfp的dll提取内存数据完成工作,把结果放到内存,VC又到内存提取结果。 首先内存操作比磁盘文件操作快,其次VC调用VFP和vfp结束返回VC的时间与监控文件再启动的时间差是数量级上的差别。
elongwang1 2014-05-08
  • 打赏
  • 举报
回复
引用 10 楼 zhao4zhong1 的回复:
效率慢不慢,耗不耗资源,不是凭你的主观想象,而是用profiler和资源管理器实际观察得到的结果来证明的。 不要迷信书、考题、老师、回帖; 要迷信CPU、编译器、调试器、运行结果。 并请结合“盲人摸太阳”和“驾船出海时一定只带一个指南针。”加以理解。 任何理论、权威、传说、真理、标准、解释、想象、知识……都比不上摆在眼前的事实! 有人说一套做一套,你相信他说的还是相信他做的? 其实严格来说这个世界上古往今来所有人都是说一套做一套,不是吗? 不要写连自己也预测不了结果的代码!
你这种需要VC和VFP随时监控磁盘文件,如果不设定个定时器,就要挂个钩子,不然一直监控的话,必须是双核以上的CPu才能胜任(而且有2核一定是100%),而且磁盘文件的读写效率本来就低,唯一的优点就是通吃,什么情况都能应付。用DLL,直接共享内存空间,而且VC可以开多线程,效率肯定DLL快三,缺点就是需要两种语言的相互配合。
allenhiman 2014-05-07
  • 打赏
  • 举报
回复
估计你说的大婶 都写了好多字了 你还是实际提出你遇到什么不解为好 范范的提问 知道的也不愿意打那么多字啊
elongwang1 2014-05-07
  • 打赏
  • 举报
回复
引用 8 楼 zhao4zhong1 的回复:
VC将请求数据写到文件a.txt,写完后改名为aa.txt VFP发现aa.txt存在时,读取其内容,调用相应功能,将结果写到文件b.txt,写完后删除aa.txt,改名为bb.txt VC发现bb.txt存在时,读取其内容,读完后删除bb.txt 以上VC可以替换为A(任何开发语言或开发环境),VFP可以替换为B(任何与A不同的开发语言或开发环境) 除非A或B不支持文件读写和文件更名。 但是谁又能举出不支持文件读写和文件更名的开发语言或开发环境呢?
你这种也是个思路,不过效率太慢了,而且很耗资源,我想用VC作壳就是既想拥有VFP强大的数据处理能力,又想在其他方面拥有VC近乎万能的功能和效率(最主要反编译vc比反编译vfp要困难)。 这个问题已经在VFP版基本得到解决了,感谢各位的回帖。虽然这个帖子没有答对的,还是按照贴数意思意思。
赵4老师 2014-05-07
  • 打赏
  • 举报
回复
VC将请求数据写到文件a.txt,写完后改名为aa.txt VFP发现aa.txt存在时,读取其内容,调用相应功能,将结果写到文件b.txt,写完后删除aa.txt,改名为bb.txt VC发现bb.txt存在时,读取其内容,读完后删除bb.txt 以上VC可以替换为A(任何开发语言或开发环境),VFP可以替换为B(任何与A不同的开发语言或开发环境) 除非A或B不支持文件读写和文件更名。 但是谁又能举出不支持文件读写和文件更名的开发语言或开发环境呢?
赵4老师 2014-05-07
  • 打赏
  • 举报
回复
共享临时文本文件这种进程之间的通讯方法相比其它方法的优点有很多,下面仅列出我现在能想到的: ·进程之间松耦合 ·进程可在同一台机器上,也可跨机,跨操作系统,跨硬件平台,甚至跨国。 ·方便调试和监视,只需让第三方或人工查看该临时文本文件即可。 ·方便在线开关服务,只需删除或创建该临时文本文件即可。 ·方便实现分布式和负载均衡。 ·方便队列化提供服务,而且几乎不可能发生队列满的情况(除非硬盘空间满) ·……
赵4老师 2014-05-07
  • 打赏
  • 举报
回复
我3楼的方法几乎可以通杀各种跨开发语言、跨操作系统功能调用问题。 就跟找人办事只需要语言沟通或递纸条一样。 所以你应该从芸芸众生过去用的跨开发语言、跨操作系统功能调用方法彻底决裂!皈依我佛!! (怎么感觉象邪教?)
elongwang1 2014-05-07
  • 打赏
  • 举报
回复
引用 2 楼 allenhiman 的回复:
估计你说的大婶 都写了好多字了 你还是实际提出你遇到什么不解为好 范范的提问 知道的也不愿意打那么多字啊
嗯,我在vfp中编译了个dll,类是mydata,函数是test,里面就一确定对话框。想在vc中调用这个vfp的dll实现这个对话框,问怎么办?网上有vc调用com的五大招,但是编译的时候说: E:\开发\VC学习\testdll1\testdll1Dlg.cpp(179) : error C2065: 'CComPtr' : undeclared identifier E:\开发\VC学习\testdll1\testdll1Dlg.cpp(179) : error C2275: 'IGetRes' : illegal use of this type as an expression e:\开发\vc学习\testdll1\debug\mydll.tlh(21) : see declaration of 'IGetRes' E:\开发\VC学习\testdll1\testdll1Dlg.cpp(179) : error C2065: 'pGetRes' : undeclared identifier E:\开发\VC学习\testdll1\testdll1Dlg.cpp(180) : error C2228: left of '.CoCreateInstance' must have class/struct/union type E:\开发\VC学习\testdll1\testdll1Dlg.cpp(181) : error C2227: left of '->Hello' must point to class/struct/union E:\开发\VC学习\testdll1\testdll1Dlg.cpp(182) : error C2228: left of '.Release' must have class/struct/union type 现在想问,对应http://bbs.csdn.net/topics/340150614这篇帖子的VFP的dll该如何创建,或者vfp的dll没问题的话,vc该如何调用?
elongwang1 2014-05-07
  • 打赏
  • 举报
回复
引用 3 楼 zhao4zhong1 的回复:
不要做A语言代码修改为B语言代码的无用功。 也不要做用A语言代码直接调用B语言代码库这样复杂、这样容易出错的傻事。 只需让A、B语言代码的输入输出重定向到文本文件,或修改A、B语言代码让其通过文本文件输入输出。 即可很方便地让A、B两种语言之间协调工作。
因为VC在数据库方面不如VFP,但在效率上和安全上又优于VFP,所以想用VC作壳,通过调用vfp的com实现对数据的操作。
赵4老师 2014-05-07
  • 打赏
  • 举报
回复
不要做A语言代码修改为B语言代码的无用功。 也不要做用A语言代码直接调用B语言代码库这样复杂、这样容易出错的傻事。 只需让A、B语言代码的输入输出重定向到文本文件,或修改A、B语言代码让其通过文本文件输入输出。 即可很方便地让A、B两种语言之间协调工作。
elongwang1 2014-05-06
  • 打赏
  • 举报
回复
顶不能让它沉了

3,245

社区成员

发帖
与我相关
我的任务
社区描述
ATL,Active Template Library活动(动态)模板库,是一种微软程序库,支持利用C++语言编写ASP代码以及其它ActiveX程序。
社区管理员
  • ATL/ActiveX/COM社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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