Groups | Blog | Home
all groups > dotnet interop > may 2006 >

dotnet interop : Accessing embedded resources in .NET DLL through COM


hoptoit
5/30/2006 4:06:59 PM
I am writing a class library in VS .NET 2005 (VB.NET specifically) that will
be called from an existing program (that I have no control over) using COM.
One of the parameters it expects is the index of an icon embedded in the
DLL. The catch is that other than a default icon that seems to be included
in the DLL automatically by Visual Studio (at index 0), none of the icons I
embed seem to be visible to the calling program.

I have tried various combinations of Build Actions, adding the icons as
Resources in the project Properties, all to no avail. Everything I can find
on the web talks about how to access embedded resources programmatically
within the context of the .NET Framework, which is not particularly useful
in this instance.

I haven't done much COM programming, so it is quite possible I am missing
something obvious, but I am at my wit's end on this one.

Does anyone have any suggestions on how to either make the resources
embedded through Visual Studio visible through COM, or know of some other
mechanism for embedding resources that is more appropriate in this context?

Thanks!
--Lance--

v-phuang NO[at]SPAM online.microsoft.com (
5/31/2006 2:10:49 AM
Hi Lance,

Thanks for your posting!

From your description, I understand that you have a .NET class library and
a legacy COM client(maybe VB6 or C++).
Now you will embedded the icon into the .NET class library and expose it to
the COM, so that the com client can access to it.
Now you want to access to the icons embedded in the .NET.

Have I fully understood you? If there is anything I misunderstood, please
feel free to let me know.
Based on my experience, we should use .NET related code to access to the
resource which is stored according to .NET namespace.(e.g. ResourceManager
class)
So can you post the code in the COM client about how will your code try to
access the icons?

Best regards,

Peter Huang

Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
HopToIt
5/31/2006 8:22:01 AM
Correct, I am writing a .NET DLL that will provide "add-in" functionality to
an existing COM executable. The COM executable specifies an interface that
it expects add-in DLLs to use.

However, I do not have the ability to modify the way the COM executable
works, so whatever code it uses to access the icons is the code I am stuck
with (so unfortunately using the .NET GetManifestResource* functions is out).


I do have access to the C++ source code, and with a little bit of searching,
it looks like the executable is using the ExtractIcon function declared in
shellapi.h (a Win32 API function, I think?), which expects a zero-based index
specifying which icon to retrieve. Here is the actual code snippet:

HICON hIcon = NULL;
int nIconIndex = m_wizard.GetIconIndex();
if (nIconIndex >= 0)
hIcon = ExtractIcon(AfxGetInstanceHandle(), m_strPath, nIconIndex);

m_wizard is the COM interface wrapper to access my DLL.
GetIconIndex() is the function in my DLL that provides an index to which
icon I want displayed.
m_strPath is the path to my DLL.

So, I guess the question is how do I embed my icons such that ExtractIcon
will be able to find them?

Thanks so much for your help,
AddThis Social Bookmark Button