How to call VC6.0 developed COM in Delphi

Source: Internet
Author: User
Tags uuid

Last wrote how in VC6.0 under Delphi write COM to invoke, originally wanted to write immediately how in Delphi call VC6.0 development of COM, because in write case program encountered a very strange problem, in my machine with VC written interface program compiled can pass. But the call will have a problem, (in the VC downward use is the same as the appearance). But with Delphi written interface program compiled, whether in VC or in the Delphi downward use is no problem. Later I put VC development interface program compiled, copy to other machine test, strange, completely no problem. After summing up to know that I have a problem with the machine. I have not yet resolved why it is not possible on my machine, on other machines. (If any friend has any idea, please contact me, I think this problem is probably because of the registration reason) not to say more. Let's just talk about it.

When the interface is developed under VC6.0, a corresponding filename is generated. IDL (Interface Definition) interface description file. (IDL's syntax is also simple, but it's important in the development of interfaces.) I read this book, a very familiar with the COM Cow xx Foreigner said, the development of COM everything starting from IDL. Of course, we're not like that. Because we don't cow xx. So I can't do that. or give it to the software to write it! Get this IDL file, available IDLtoPas.exe tools (NND, I find this tool for six months have not found, and now there is no, heard in the Delphi6.0. Therefore, only by hand to the IDL file using Pascal to describe, it is not difficult, there are symbols of the conversion work, the IDL file into the file described by Pascal. So we can make a call to its interface. Of course, when calling an interface, there is no need to interface. DLL file and. idl file, the IDL file is used to generate the corresponding Pascal file, after the generation of good, IDL can not be. The. dll file is an interface-compiled dynamic library. This is known to all. That's all you have to say. Let's give you a little example.

1, with VC6.0 to generate an interface program, here I do not say, I generated the program only one interface called Itestcom one of the methods is: ShowMsg (), Display a message dialog box.

2, the above generated the program to compile, the generated IDL file used under Delphi with Pascal Description:

VC generated IDL file:

// MaAtl.idl : IDL source for MaAtl.dll
//
// This file will be processed by the MIDL tool to
// produce the type library (MaAtl.tlb) and marshalling code.
import "oaidl.idl";
import "ocidl.idl";
[
 object,
 uuid(78313A6E-FBA7-11D5-8094-00E04C4EA60F),
 dual,
 helpstring("ITestCom Interface"),
 pointer_default(unique)
]
interface ITestCom : IDispatch
{
 [id(1), helpstring("method ShowMsg")] HRESULT ShowMsg();
};
[
 uuid(78313A62-FBA7-11D5-8094-00E04C4EA60F),
 version(1.0),
 helpstring("MaAtl 1.0 Type Library")
]
library MAATLLib
{
 importlib("stdole32.tlb");
 importlib("stdole2.tlb");
[
  uuid(78313A6F-FBA7-11D5-8094-00E04C4EA60F),
  helpstring("TestCom Class")
 ]
 coclass TestCom
 {
  [default] interface ITestCom;
 };
};

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.