Click here to Skip to main content
15,891,136 members
Home / Discussions / C#
   

C#

 
GeneralRe: GetWindowText/GetForegroundWindow Pin
pat27088124-Aug-04 11:44
pat27088124-Aug-04 11:44 
GeneralCopying txt input from 1 form to the other Pin
steve_rm24-Aug-04 5:14
steve_rm24-Aug-04 5:14 
GeneralRe: Copying txt input from 1 form to the other Pin
Steve Maier24-Aug-04 5:26
professionalSteve Maier24-Aug-04 5:26 
GeneralRe: Copying txt input from 1 form to the other Pin
Heath Stewart24-Aug-04 8:57
protectorHeath Stewart24-Aug-04 8:57 
GeneralRe: Copying txt input from 1 form to the other Pin
steve_rm25-Aug-04 3:02
steve_rm25-Aug-04 3:02 
GeneralRe: Copying txt input from 1 form to the other Pin
LongRange.Shooter25-Aug-04 4:44
LongRange.Shooter25-Aug-04 4:44 
Generalproject options (advice) Pin
HudsonKane24-Aug-04 3:13
HudsonKane24-Aug-04 3:13 
GeneralRe: project options (advice) Pin
Steve Maier24-Aug-04 4:45
professionalSteve Maier24-Aug-04 4:45 
I did something similar in a project for my last job. There were two approaches that we took. The first was to expose the .Net (C#) object with a COM interface so that unmanaged code could use the objects like a normal COM object. The second way is to compile your unmanaged code to include the managed extensions. Then you can just create a new variable of the class type that is in the C# DLL that you make and just use it.

I prefer the second method, but there are a few things that you have to do to be able to do this. I only have VS 2005 installed here now, so this is from memory and a small test that I did here.


  • Turn on the managed extensions in the project. This is probably in Configuration Proerties labeled something like "Common Language runtime support"
  • Add the following code to your stdafx.h or similar file.
    #using < mscorlib.dll >
    
    using namespace System;
    using namespace System::Runtime::InteropServices;

  • Add the reference to your C# DLL to the unmanged project
  • Create a manged variable using code like this:
    gcroot< ClassLibrary1::Class1* > c = new ClassLibrary1::Class1();
    
    int t=c->MyProperty;
    
    CString buff;
    buff.Format("data = %d",t);
    MessageBox(buff);
    c->ShowIt();

  • Use the class instance using a ->


Using this method you can make the C# library just be a class library project and call the classes from it in your unmanaged code.

Steve Maier, MCSD MCAD
GeneralRe: project options (advice) Pin
HudsonKane24-Aug-04 5:33
HudsonKane24-Aug-04 5:33 
GeneralRe: project options (advice) Pin
HudsonKane24-Aug-04 5:36
HudsonKane24-Aug-04 5:36 
GeneralRe: project options (advice) Pin
Steve Maier24-Aug-04 7:13
professionalSteve Maier24-Aug-04 7:13 
GeneralRe: project options (advice) Pin
HudsonKane24-Aug-04 8:19
HudsonKane24-Aug-04 8:19 
GeneralWeb application config Pin
jzb24-Aug-04 3:09
jzb24-Aug-04 3:09 
GeneralRe: Web application config Pin
Steven Campbell24-Aug-04 3:51
Steven Campbell24-Aug-04 3:51 
QuestionHow can I pass byte array from C++ to c# ? Pin
neoksd24-Aug-04 2:31
neoksd24-Aug-04 2:31 
AnswerRe: How can I pass byte array from C++ to c# ? Pin
billb211224-Aug-04 3:31
billb211224-Aug-04 3:31 
GeneralRe: How can I pass byte array from C++ to c# ? Pin
neoksd24-Aug-04 4:16
neoksd24-Aug-04 4:16 
GeneralRe: How can I pass byte array from C++ to c# ? Pin
billb211224-Aug-04 5:45
billb211224-Aug-04 5:45 
AnswerRe: How can I pass byte array from C++ to c# ? Pin
Heath Stewart24-Aug-04 8:03
protectorHeath Stewart24-Aug-04 8:03 
GeneralRe: How can I pass byte array from C++ to c# ? Pin
neoksd26-Aug-04 15:23
neoksd26-Aug-04 15:23 
GeneralRe: Declaration Default Argument Values Pin
S Sansanwal23-Aug-04 23:54
S Sansanwal23-Aug-04 23:54 
GeneralRe: Declaration Default Argument Values Pin
Heath Stewart24-Aug-04 8:09
protectorHeath Stewart24-Aug-04 8:09 
GeneralHosting Managed Controls in MFC Pin
Amir Harel23-Aug-04 23:13
Amir Harel23-Aug-04 23:13 
Generaldatabound list with customisable filter Pin
..Hubert..23-Aug-04 23:03
..Hubert..23-Aug-04 23:03 
GeneralIP-Tunnel Pin
erina54823-Aug-04 22:55
erina54823-Aug-04 22:55 

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.