Under VC 6.0 how to invoke Delphi development in the process of COM

Source: Internet
Author: User
Tags zip

Source code package has two zip files, which delphicallvccom.zip for Delphi to invoke VC COM components, Vccalldelphicom.zip for VC call Delphi COM components

Because my language level is very poor, examination University 150 total score, I took a 60 points. The foreign language is also, the junior high school pass once, the examination pass once. Other times seem to have never passed. So I do not write articles, because I write 100 words of the article, at least eight or nine typos. Haha ... it's a careless. You don't say I'm really a horse. So there are mistakes in the following article, please understand the old people a lot. Who told you to read my article? Let's talk about the right thing!

I contact the time of COM is not long, is read this about component reuse of the book, just let me to com produce sex (hing) interesting. So I want to try COM binary-level reuse is not easy to use. In the process of developing a company project, I wrote a database operation in COM mode. (written in Delphi). I think this project is over. But after a while, the boss called to write another small program, I detailed analysis of the functional requirements. Haha, the original and I use the COM development of a project data operation part. So just think of reuse. But now the program is to write in VC source program based on the database operation. So, how to use Delphi to write a good COM to VC! After looking for information, finally found, the original as long as the Delphi write COM generated idl file with MIDL.EXE compiled. h and _i.c files. So the VC can be used. But this MIDL.EXE document is really not good, to now I still won't use. I only first in VC generated an ATL project file TTT and an empty interface file, so that the compilation generated TTT.H,TTT.IDL,TTT_I.C. Haha ... no way, who told me not to use Midl.exe Ah, only to make this stupid way. I copied the Rh.idl file under Delphi to the TTT and renamed it Ttt.idl compiled. The generated ttt.h, TTT_I.C is what I want. This generates the desired VC can call the two interface files. Here is the case:

1, use Delphi5.0 to generate the COM service program in the process:

Delphi5.0 write in-process COM service I don't say it here anymore. The "MADLL.DPR" I generated in the "article Case" directory is a COM program written with Delphi, compiled to generate Madll.idl and Madll.dll files.

2. Invoke COM Service interface with VC6.0:

Compile the Madll.idl files generated with Delphi5.0 into. h and _i.c files. If it's not for Midl.exe. Can be done in the way I said above.

Build the Macpp project, it's a dialog box. Add the generated madll.h file to the system. This allows you to see the Imacom interface declaration in the ClassView.

Define in Madlg.cpp

//申明接口返回和接口类型
HRESULT hr;
ImaCom *pmaCom = NULL;
在OnButton1中调用
void CMacppDlg::OnButton1()
{
// TODO: Add your control notification handler code here
// 初始化COM
hr = CoInitialize(0);
// 使用SUCCEEDED 宏并检查我们是否能得到一个接口指针
if(SUCCEEDED(hr))
{
  hr = CoCreateInstance( CLSID_maCom, NULL, CLSCTX_INPROC_SERVER,
IID_ImaCom,
(void**) &pmaCom);//生成接口调用类场
pmaCom->ShowMa(NULL,(WORD)GetSafeHwnd());//调用COM方法。
  pmaCom->Release();
  CoUninitialize();
}
}

The Madll.dll must be registered before running this program, otherwise the call will not succeed.

Register just enter: regsvr32 madll.dll in the Start-Run dialog box. Make sure it's okay. Of course after the regsvr32 to follow is the directory where Madll.dll. When you want to log off, this is regsvr32 madll.dll/u on the line.

All right. Now you can compile the macpp and run it to invoke the interface. This is simply an interface call made to COM Delphi5.0 written under VC6.0. In turn, COM can be developed under VC6.0 and invoked under Delphi5.0. A demonstration is given in the code that is included with this article.

Thank you for taking time to read, I will try to learn Chinese. At least in the future article will appear a few typos.

This article supporting source code

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.