I have written a C# executable, which I run regasm on to register it as a COM
class for use in some unmanaged C++ code.
Im the C++ code, I import the mscorlib.tlb and my .tlb file, declare some
interface variables, and start COM just fine... but when I try to get an
IUnknown interface pointer, or my custom interface pointer for the class I
exposed, I get the following error: "Class not registered" -OR- something
like could not find file.
It does not list what file.
What am I doing wrong in the exporting of this C# class?
Thanks in advance
Andrew S. Giles
Andrew S. Giles - 09 Dec 2004 16:17 GMT
The actual other message is: "The system cannot find the file specified"
I am fairly sure that something is not being registered properly... but I do
not know how to fix this.
Andrew
> I have written a C# executable, which I run regasm on to register it as a COM
> class for use in some unmanaged C++ code.
[quoted text clipped - 12 lines]
>
> Andrew S. Giles
Eric Carlson - 09 Dec 2004 16:53 GMT
I think your c# executable needs to be in the same directory as your c++
program...
or
You should use the /Codebase option on the Regasm,
or
you should be using gacutil.exe to register your c# exe into the global
assembly cache. (you need to strong name it for this)
> The actual other message is: "The system cannot find the file specified"
>
[quoted text clipped - 19 lines]
> >
> > Andrew S. Giles
Andrew S. Giles - 09 Dec 2004 17:27 GMT
OK, two of the 3 suggestions you made require me to give this
class/assembly/whatever it is now a "strong name"
I only have one example of doing this froma book, and that code gives me
compilation errors.
How does one give a class a strong name?
Andrew
> I think your c# executable needs to be in the same directory as your c++
> program...
[quoted text clipped - 31 lines]
> > >
> > > Andrew S. Giles
Eric Carlson - 09 Dec 2004 17:39 GMT
Sorry, forgot the codebase option requires strong name too.
It's easy. Do you have .Net SDK docs? Lookup "sn.exe"
This utility creates and key pair and outputs it to a file that you specify
such as mykey.snk, which you include in your project directory, and then add
the following line into your AssemblyInfo.cs file at the bottom (should
already be a line listed)
[assembly: AssemblyKeyFile("..\\..\\myKey.snk")]
You have to use the backslashes because it is referencing from the debug or
release directory where the assembly outputs to.
Does that help?
Andrew S. Giles - 09 Dec 2004 17:57 GMT
OK, Ive found it in the assemblyinfo.cs file now.
Will add my own name, and then run the sn.exe on it
sn -k filename.snk
Then I should be able to use /codebase or gacutil on the dll, right?
Andrew
> Sorry, forgot the codebase option requires strong name too.
>
[quoted text clipped - 11 lines]
>
> Does that help?
Eric Carlson - 09 Dec 2004 19:16 GMT
Correct.
If you use the gacutil, the assembly will be loaded in the Global Assembly
Cache (c:\windows\assembly) so that it can be used by all programs.
If you use the codebase option on Regasm.exe, the location of your exe will
be written into the registry, so that programs can find it.