简体   繁体   中英

WIN32::OLE calling .Net dll

I just want to confirm one thing: Must you have a constructor with no params for the .NET assembly for it to be called like a regular COM component (with Win32::OLE -> new())? If a dll has no comvisible class with such constructor, you will not be able to call it by Win32::OLE -> new().

Yes. You need a public and default constructor. http://msdn.microsoft.com/en-AU/library/ms182203(v=vs.80).aspx

If your class does not have any public constructor then you do not need to create one since a public default constructor is automatically added for you : http://msdn.microsoft.com/en-us/library/aa645608(v=vs.71).aspx ie:

This:

class Message
{
   object sender;
   string text;
}

is same as:

class Message
{
   object sender;
   string text;
   public Message(): base() {}
}

However if you have a constructor with some arguments then you must manually provide a public default constructor.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM