Welcome Guest! You need to login or register to make posts.

Notification

Icon
Error

Options
Go to last post Go to first unread
Dmitry  
#1 Posted : Monday, February 18, 2008 3:36:47 PM(UTC)
Dmitry

Rank: Advanced Member

Groups: Member, Administration, Moderator
Joined: 8/3/2003(UTC)
Posts: 1,070

Thanks: 1 times
Was thanked: 12 time(s) in 12 post(s)
Sometimes our customers ask us how to expose Graphics Mill for .NET assemblies to COM. Unfortunately Graphics Mill assemblies cannot be exposed to COM by-design. But there is a trick: you can implement COM wrapper - .NET assembly which has public methods performing some operations using Graphics Mill but not showing Graphics Mill types outside.

We will see how to implement the wrapper in action in this post. The wrapper will expose resize functionality of Graphics Mill. So let us create this wrapper step by step.

1. Create class library.

2. Add reference to Aurigma.GraphicsMill.dll.

3. Define the functionality you wish to expose in a managed interface, and have your managed object implement this interface. Let us examine the following sample: suppose you need to expose resize functionality. You should create managed interface, like this:

Code:

[Guid("694C1820-04B6-4988-928F-FD858B95C880")]
public interface IResizeWrapper
{
    void Resize(string srcFileName, string destFileName, 
        short newWidth, short newHeight);
}


And class which implements this interface:

Code:

[Guid("9E5E5FB2-219D-4ee7-AB27-E4DBED8E123E")]
[ClassInterface(ClassInterfaceType.None)]
public class ResizeWrapper: IResizeWrapper
{
    public ResizeWrapper()
    {
    }

    public virtual void Resize(string srcFileName, string destFileName, 
        short newWidth, short newHeight)
    {
        …
    }
}


Pay attention that this class has the only method which resizes images with the following parameters: srcFileName – source image file name, destFileName – destination image file name, newWidth – new width of image in pixels, newHeight – new height of image in pixels.

4. Every interface and class needs a Guid attribute set before the interface name. To generate the unique guid, use the guidgen.exe utility and select the Registry Format.
Code:

[Guid("9E5E5FB2-219D-4ee7-AB27-E4DBED8E123E")]


5. Class needs to be marked with ClassInterface attribute:
Code:

[ClassInterface(ClassInterfaceType.None)]


6. Open AssemblyInfo.cs file and mark assembly as com visible:
Code:

[assembly: ComVisible(true)]


7. Before we build the COM object we have to register the object for COM Interop. To do this: right click the project name in the Solution Explorer. Click Properties. Click Configuration, Build. Expand the output section. Set the Register for COM Interop to true.

8. In order for the COM object to be exposed, your class library assembly must also have a strong name. To create a file with strong name use the utility sn.exe:
Code:

sn -k AurigmaCOMWrappper.snk

Then you need to modify signing settings in project settings: right click the project name in the Solution Explorer. Click Properties. Click Signing tab, choose Sign the assembly and specify the file created before.

9. Compile the assembly.

10. Expose the assembly using Regasm.exe utility:
Code:

regasm Aurigma.COMWrapper.dll


That is all, now you can use this wrapper assembly in your COM applications.

You can find complete sample wrapper attached to this topic.

Edited by user Tuesday, July 15, 2008 6:52:29 PM(UTC)  | Reason: Not specified

File Attachment(s):
COMWrapper.zip (5kb) downloaded 24 time(s).
Sincerely yours,
Dmitry Sevostyanov

UserPostedImage Follow Aurigma on Twitter!
Users browsing this topic
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.