Click here to Skip to main content
15,891,248 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have create the class library .dll file in C#.NET . then register this file using the regasm.exe command when i will register this file it display it's access path as mscoree.dll file,but my dll file path is another(C:\program files\mydll.dll) . when i have used this in ActiveX control into the another software like (simantic HMI wincc flexible ) ,drag this control into the screen of the wincc it display the error message as
failed to create graphics object from type control 
Posted
Updated 20-Nov-11 20:01pm
v3

Try this article: "Exposing Windows Forms Controls as ActiveX controls" by Morgan Skinner[^].

... edit #1 ...

this question evidently refers to an attempt to use C# dll inside "SIMATIC WinCC Open Architecture"[^]

It appears the OP has used regasm.exe to "register," the C# DLL, then, inside WinCC, tried to import it, expecting its visual elements to show up.

Since the WinCC software is a dedicated system for developing industrial automation solutions (undoubtedly very expensive), I think the best thing to do, is to seek clarification from the WinCC support at Siemens.

The key questions is: does WinCC IDE allow .NET components of any type ... those components, of course being dependent on the .NET FrameWork. If this software does allow use of .NET created elements with graphic elements, then I would expect somewhere in the WinCC documentation, or the Siemens website, there is a code example, or guidelines on how to use them, and what exactly can be used.

Well, our friend Google suggests WinCC does allow .NET components:[^]

I'd suggest studying the links on that Google page that appear to specifically talk about using .NET controls in WinCC.

Also, why not ask questions on whatever forums Siemens offers on-line: surely for this level of very expensive software they have on-line,or e-mail, support ?

... end edit #1 ...

good luck, Bill
 
Share this answer
 
v4
Comments
vrushali katkade 21-Nov-11 2:00am    
thanks for reply i already refer this code & used this code in my coding but it will show the same message
Maxim Kartavenkov 7-Oct-12 6:51am    
Actually not the solution, reference to an article without understanding of the issue itself, and the article does not handle all aspects of embedding COM/OLE .NET control in any types of application requirements, just basic approach.

So, I have voted your answer as #1.

Maxim.
BillWoodruff 7-Oct-12 9:49am    
I could care less how you vote. But, for this type of question, which is sketchy, involves complex 3rd. party software, I think the OP is lucky I took the time to give an answer that involved research on my part, and I think it's quite appropriate as "solution" rather than "comment." Do you think "Solution 2" here is a solution, since it simply recommends my solution :) ? Why didn't you down-vote that one, as well.
Maxim Kartavenkov 7-Oct-12 10:22am    
No, I'm not thinking that the "Solution 2" is the solution. I post my solution here with brief overview in there the issue can be and how it can be solved. I downvote your anwser bcs of next: 1. Actually, solution with words "not possible" "not allowed" and similar can't be dedicated as "Solution". 2. You are not reseraching in actual problems which are possible to be in there which are makes your answer unusable. 3. As in question he mentioned that he available to select his control but it can't be created due error information he specified - than article u mean is useless.
Article suggested by BillWoodruff is simple and well explained I like it, please follow it and if still getting problem share us your code or stub so someone can look it.

rushi
 
Share this answer
 
Comments
vrushali katkade 21-Nov-11 1:59am    
i already refer this code & used this code in my coding but it will show the same message
BillWoodruff 7-Oct-12 10:03am    
Joshi, this is not really a "solution:" saying you like someone else's solution is fine, but you have added no original content here. This is appropriate as a comment, but not a solution.
Hello,

The way is described in Morgan Skinner article is only the basic stuff which you should handle.

Actually Winform conrol handle all aspects of OLE/COM control but 2 of them (I think mandatory) are missed.
1. It does not allow change client site once it already activated and window handle created (see IOleObject.SetClientSite in MSDN).
2. It does not support manual drawing (see IViewObject.Draw in MSDN)

The first issue appear once Control.Handle and parent is set, but the application try to changed. You should use a WinAPI DestroyWindow and SetParent (DestroyWindow dispose the handle and it will be recreated by .NET with new parent).

The second issue appear once the control activated with the manually drawing - this can be in case if application wan't to draw the control content - it can be it own DC or the printer DC (Usually the applications with printing supports and allows to use COM/OLE controls activate control with manual draw parameter). The proper way to handle that is to make manual drawing, but at least you can just call you base method Control.DrawToBitmap to draw content on Bitmap and then draw that Bitmap into given DC.

To make it work you should better to make the handling interfaces manually, most of the calls can be just forwarded to AxHost but some methods better to override.
Interface necessary to implement on your object (Thats minimal list but some applicaions may require more): IProvideClassInfo, IProvideClassInfo2, IQuickActivate, IViewObject, IViewObject2, IOleObject, IOleControl, IOleInPlaceObject, IOleInPlaceObjectWindowless, IOleInPlaceActiveObject, IOleWindow.

Some applications may requre persits storage or persist stream initialization interfaces so keep that in mind.

You should set the reqistry entry to mark your .NET Control as COM/OLE Control as described in Morgan Skinner article but also with the changes.

Registration function:
C#
[ComRegisterFunctionAttribute]
[RegistryPermissionAttribute(SecurityAction.Demand, Unrestricted=true)]
public static void RegisterFunction(Type _type)
{
    // Check your class type here 
    if (_type != null && _type.IsSubclassOf(typeof(MyCOMControl))) 
    {
        string sCLSID = "CLSID\\" + _type.GUID.ToString("B");
        try
        {
            RegistryKey _key = Registry.ClassesRoot.OpenSubKey(sCLSID, true);
            try
            {
                Guid _libID = Marshal.GetTypeLibGuidForAssembly(_type.Assembly);
                int _major, _minor;
                Marshal.GetTypeLibVersionForAssembly(_type.Assembly, out _major, out _minor);
                using (RegistryKey _sub = _key.CreateSubKey("Control")) { }
                using (RegistryKey _sub = _key.CreateSubKey("MiscStatus")) { _sub.SetValue("", "0", RegistryValueKind.String); }
                using (RegistryKey _sub = _key.CreateSubKey("TypeLib")) { _sub.SetValue("", _libID.ToString("B"), RegistryValueKind.String); }
                using (RegistryKey _sub = _key.CreateSubKey("Version")) { _sub.SetValue("", String.Format("{0}.{1}", _major, _minor), RegistryValueKind.String); }
                using (RegistryKey _sub = _key.CreateSubKey("Control")) { }
                using (RegistryKey _sub = _key.CreateSubKey("InprocServer32")) { _sub.SetValue("", Environment.SystemDirectory + "\\" + _sub.GetValue("", "mscoree.dll"), RegistryValueKind.String); }
            }
            finally
            {
               _key.Close();
            }
        }
        catch
        {
        }
    }
}

Unregister function:
C#
[ComUnregisterFunctionAttribute]
[RegistryPermissionAttribute(SecurityAction.Demand, Unrestricted=true)]
public static void UnregisterFunction(Type _type)
{
    //Check Your type here
    if (_type != null && _type.IsSubclassOf(typeof(MyCOMControl)))
    {
        try
        {
            string sCLSID = "CLSID\\" + _type.GUID.ToString("B");
            Registry.ClassesRoot.DeleteSubKeyTree(sCLSID);
        }
        catch
        {
        }
    }
}

As in there for full solution a lot of code; and I'll show other underwater stones in the article how to proper make that in details. I'll add link to comment here once I have time to post an article.

Again for debators (Especially for Bill): I repeating if you don't know how to make that not write that it isn't possible - maybe better to start learning?

Regards,
Maxim.
 
Share this answer
 
Comments
BillWoodruff 7-Oct-12 10:00am    
"(Especially for Bill): I repeating if you don't know how to make that not write that it isn't possible"

You, Sir, are misrepresenting my words: I never said what the OP asked for is not possible. And, it is inappropriate for you to make this kind of mis-representation in a solution.

It is interesting, and somewhat amusing, that your "solution" above has no links in it, but is based on using a link given in my solution, which you now claim is not a solution :)

But, I would never down-vote your solution based on some personal reaction. And, the content of your solution is not in an area where I have the expertise to evaluate it. I sincerely hope the OP and others find it useful: if not, they can vote based on their evaluation.

If some aspect of a post by you upset me, I'd respond directly to you with a comment.

If you really feel a "solution" is not an answer, you can click on the red "Report Flag," and select the option: "Not an answer."

I suggest you re-consider your comments here.

best, Bill
Maxim Kartavenkov 7-Oct-12 10:38am    
Solution is not based on that article - it is describes that article does not handled all aspects which can be with the OLE/COM Controls in .NET and what is missed in .NET for that. If you didn't implement that things from scratch in C# you can't understand the issue.
You had downvote one of my solution without any reason, and even have no reply on comment I posted. I check questions you had answered and found few which are totally wrong I improve them and downvote one with the reason I described.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900