Click here to Skip to main content
15,886,035 members
Home / Discussions / C#
   

C#

 
QuestionHow record behavior of a process in windows? Pin
saeedmir17-May-16 7:26
saeedmir17-May-16 7:26 
AnswerRe: How record behavior of a process in windows? Pin
BillWoodruff17-May-16 7:46
professionalBillWoodruff17-May-16 7:46 
GeneralRe: How record behavior of a process in windows? Pin
saeedmir17-May-16 7:52
saeedmir17-May-16 7:52 
GeneralRe: How record behavior of a process in windows? Pin
Eddy Vluggen17-May-16 8:03
professionalEddy Vluggen17-May-16 8:03 
Rant[REPOST] How record behavior of a process in windows? Pin
Richard Deeming17-May-16 7:49
mveRichard Deeming17-May-16 7:49 
QuestionObject is currently in use elsewhere C# - System.Drawing Exception Pin
Django_Untaken16-May-16 21:56
Django_Untaken16-May-16 21:56 
AnswerRe: Object is currently in use elsewhere C# - System.Drawing Exception Pin
Pete O'Hanlon16-May-16 23:09
mvePete O'Hanlon16-May-16 23:09 
Question[Updated] AnyCPU and exposing functionality via COM Pin
Matt T Heffron16-May-16 13:51
professionalMatt T Heffron16-May-16 13:51 
(I'm not sure if this would be better asked in the COM forum... or QA...)

Is there a way to implement C#-implemented functionality via COM (for adding to legacy code) in such a way that I need build only an AnyCPU targeted dll that can then be used via COM either 32 or 64 bit?

================
Update May 18, 2016:
As it turns out, setting the build target to AnyCPU and selecting the "Register for COM interop" in the build settings does work. It appears to register the class in both HKCR and HKCR\Wow6432Node\CLSID (and the interfaces and type library in both, as well).

In my defense, this was originally written in C#, and the 32 bit COM requirement was added, so I first went down the explicit 32 bit COM path, and then I tried to add the 64 bit COM. If I had known about the COM up front I probably would have just done it this way in the first place.

And lest anyone blame the provider of the requirements...
I started this side project because I overheard coworkers discussing how to solve this conceptual issue and what they were thinking was only going to give the appearance of solving the issue. I thought that the correct solution shouldn't be difficult, so I started. When I told them what I'd accomplished, then they informed me of the COM requirement (for use by the legacy application).
================

I have a C# assembly that implements some functionality and it works fine when invoked from within C#.
There's one entry point class which implements the functionality, and exposes a support class's functionality via another interface.
Like:
C#
public class DSS
{
  // implement functionality, methods, etc. including:
  public ITSF TSF { get; private set; }
}
public interface ITSF
{
  string Prop1 { get; set; }
  // etc.
}


I have enabled COM using the [assembly: ComVisible(true)] in the AssemblyInfo.cs.
I then added [ComVisible(false)] for things I didn't want visible to COM. (Doing it the other way around didn't seem to do the "right thing".)
C#
[ComVisible(false)]
public class DSS
{
  // implement functionality, methods, etc. including:
  public ITSF TSF { get; private set; }
}
[Guid("...")]
[InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
public interface ITSF
{
  string Prop1 { get; set; }
  // etc.
}

I wrote a separate class to wrap the entry point class, and it implements an interface to expose the functionality in a COM-friendly way. (I.e., different names for overloaded methods, ...)
It inherits from the DSS class.
Like:
C#
[Guid("...")]
[ClassInterface(ClassInterfaceType.None)]
public class DSScom : DSS, IDSS
{
  // implement functionality, methods, etc. including:
  public ITSF TSF { get; private set; }
}
[Guid("...")]
[InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
public interface IDSS
{
  ITSF TSF { get; }
  // etc.
  // Different methods from the DSS class
}


I then added the "Register for COM interop" setting in the project properties.
So far, so good. This all builds. (Yes I needed to run Visual Studio 2013 as Administrator...)

Then I wanted to build for both 32 and 64 bit. (It isn't clear if the legacy application will be converted to 64 bit when it uses this via COM.)
So I added two additional build configurations (Debug32 and Release32) and set the Platform target to either 64 or 32 appropriate for the configurations.
Trying to build both configurations would fail, apparently when it was trying to unregister the previously registered, other size, dll, before registering what it had just built.
Side note: There are different versions of regasm.exe for 64 and 32. I managed to get this working, I think, by unchecking the "Register for COM interop" and adding a post-build step that registers the dll with the correct regasm.exe. At least, it doesn't fail and I think the registry info is correct. What's the easiest way to check both sizes of the COM implementation? Any suggestions?

So all of this seems to work but is there an easier way to do this so that I don't have to do all of the size-specific .BAT file PATH hackery and separate registrations? Is there a way to just build for AnyCPU, and register the COM to "just work" in 32 and/or 64 bit?

Thanks,
Matt
"Fairy tales do not tell children the dragons exist. Children already know that dragons exist. Fairy tales tell children the dragons can be killed."
- G.K. Chesterton


modified 18-May-16 12:50pm.

AnswerRe: AnyCPU and exposing functionality via COM Pin
Garth J Lancaster16-May-16 16:28
professionalGarth J Lancaster16-May-16 16:28 
GeneralRe: AnyCPU and exposing functionality via COM Pin
Matt T Heffron17-May-16 7:20
professionalMatt T Heffron17-May-16 7:20 
Questionsearch quickly Pin
Denis Tarasov16-May-16 13:26
Denis Tarasov16-May-16 13:26 
AnswerRe: search quickly Pin
OriginalGriff16-May-16 19:27
mveOriginalGriff16-May-16 19:27 
QuestionHow to create http client server application in C#? Pin
Jaimesh.241115-May-16 21:23
Jaimesh.241115-May-16 21:23 
AnswerRe: How to create http client server application in C#? Pin
Richard MacCutchan15-May-16 22:31
mveRichard MacCutchan15-May-16 22:31 
QuestionHow can i protect c# .net Code to be decompile? Pin
Member 1243103913-May-16 6:39
Member 1243103913-May-16 6:39 
AnswerRe: How can i protect c# .net Code to be decompile? Pin
Eddy Vluggen13-May-16 7:12
professionalEddy Vluggen13-May-16 7:12 
GeneralRe: How can i protect c# .net Code to be decompile? Pin
Nathan Minier14-May-16 3:02
professionalNathan Minier14-May-16 3:02 
GeneralRe: How can i protect c# .net Code to be decompile? Pin
Eddy Vluggen14-May-16 5:12
professionalEddy Vluggen14-May-16 5:12 
AnswerRe: How can i protect c# .net Code to be decompile? Pin
BillWoodruff13-May-16 8:52
professionalBillWoodruff13-May-16 8:52 
GeneralRe: How can i protect c# .net Code to be decompile? Pin
Sascha Lefèvre13-May-16 10:13
professionalSascha Lefèvre13-May-16 10:13 
GeneralRe: How can i protect c# .net Code to be decompile? Pin
BillWoodruff13-May-16 22:26
professionalBillWoodruff13-May-16 22:26 
GeneralRe: How can i protect c# .net Code to be decompile? Pin
PrateekM13-May-16 23:15
PrateekM13-May-16 23:15 
GeneralRe: How can i protect c# .net Code to be decompile? Pin
Sascha Lefèvre14-May-16 1:01
professionalSascha Lefèvre14-May-16 1:01 
AnswerRe: How can i protect c# .net Code to be decompile? Pin
Sascha Lefèvre13-May-16 10:42
professionalSascha Lefèvre13-May-16 10:42 
AnswerRe: How can i protect c# .net Code to be decompile? Pin
Patrice T14-May-16 3:15
mvePatrice T14-May-16 3:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.