Click here to Skip to main content
15,922,696 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: dialogs (perhaps modal) that dismiss upon losing focus Pin
jonathanleebrown4-May-04 9:30
jonathanleebrown4-May-04 9:30 
GeneralRe: dialogs (perhaps modal) that dismiss upon losing focus Pin
David Crow4-May-04 10:07
David Crow4-May-04 10:07 
GeneralRe: dialogs (perhaps modal) that dismiss upon losing focus Pin
jonathanleebrown4-May-04 10:14
jonathanleebrown4-May-04 10:14 
GeneralBroadcasting a message Pin
#realJSOP4-May-04 7:24
professional#realJSOP4-May-04 7:24 
GeneralRe: Broadcasting a message Pin
David Crow4-May-04 8:27
David Crow4-May-04 8:27 
GeneralRe: Broadcasting a message Pin
#realJSOP4-May-04 8:49
professional#realJSOP4-May-04 8:49 
GeneralRe: Broadcasting a message Pin
David Crow4-May-04 9:00
David Crow4-May-04 9:00 
Generalmarshalling COM to .NET problem Pin
Member 9300224-May-04 7:03
Member 9300224-May-04 7:03 
Could someone please help with marshalling to .NET. I posted this question here, not in C#, 'cause I know for sure the mistake is somewhere in .idl or cpp file.
I have a Win32 C++ project with the following three files:

//tlbsamp.cpp///////////////////////////////////////////////////
#include <windows.h>
interface ITest{bool MyFunc();};
class Test:public ITest{
int i;
public:
Test(){i=10;}
int MyFunc(){return i;}
};

ITest* __stdcall MyDll_CreateTest(){
return new Test();
}
int __stdcall MyDll_CreateInt(){
return rand();}

BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved )
{return TRUE;}
//tlbsamp.def//////////////////////////////////////////////////////////
LIBRARY TLBSamp
DESCRIPTION 'Sample DLL'
EXPORTS
MyDll_CreateTest
MyDll_CreateInt
//tlbsamp.idl/////////////////////////////////////////////////////////////
import "oaidl.idl";
import "ocidl.idl";
[ uuid(983EE63A-7FB0-494a-AD63-14F48347DB7A), lcid(0x0409), version(1.0) ]
library TLBSample
{
[object,uuid( 1F707072-05C6-4501-AD74-CFD57AB8002C)]
interface ITest:IUnknown
{int MyFunc ();}

[ version(1.0), dllname("TLBSamp.dll")]
module MyDllFunctions
{
[entry("MyDll_CreateTest")]
ITest* __stdcall CreateTest();
[entry("MyDll_CreateInt")]
int _stdcall CreateInt();
} };


I am compiling the project and get tlbsamp.dll ,tlbsamp.tlb, tlbsamp.lib, then I create a c# project, AddReference->COM->
Browse, all the .tlb file. In object browser I can see my ITest interface with MyFunk function. Here's the c# code.

using System;
using System.Runtime.InteropServices;
using TLBSample;
namespace Test_Call_MSDN_Dll
{
class Class1
{
[DllImport(@"E:\MyProgs\NET\TLBSamp\debug\tlbsamp.dll")]
public static extern TLBSample.ITest MyDll_CreateTest();

[DllImport(@"E:\MyProgs\NET\TLBSamp\debug\tlbsamp.dll")]
public static extern Int32 MyDll_CreateInt();
[STAThread]
static void Main(string[] args)
{
Console.WriteLine(MyDll_CreateInt().ToString());//OK-works fine
ITest spClass=MyDll_CreateTest();//ExecutionEngineException(???)
Console.WriteLine(spClass.MyFunc().ToString());
Сonsole.Read();
}
}
}


What am I doing wrong?
Thanks in advance!
GeneralRe: marshalling COM to .NET problem Pin
Mike Dimmick4-May-04 11:26
Mike Dimmick4-May-04 11:26 
GeneralRecompiling Everything Pin
Jeff Bogan4-May-04 6:41
Jeff Bogan4-May-04 6:41 
GeneralRe: Recompiling Everything Pin
Antony M Kancidrowski4-May-04 6:50
Antony M Kancidrowski4-May-04 6:50 
GeneralRe: Recompiling Everything Pin
Jeff Bogan4-May-04 7:05
Jeff Bogan4-May-04 7:05 
GeneralShared Data Problem Pin
sweep1234-May-04 6:03
sweep1234-May-04 6:03 
GeneralRe: Shared Data Problem Pin
Michael Dunn4-May-04 6:07
sitebuilderMichael Dunn4-May-04 6:07 
GeneralRe: Shared Data Problem Pin
Rick York4-May-04 6:27
mveRick York4-May-04 6:27 
GeneralRe: Shared Data Problem Pin
sweep1234-May-04 6:36
sweep1234-May-04 6:36 
GeneralRe: Shared Data Problem Pin
Rick York4-May-04 11:02
mveRick York4-May-04 11:02 
GeneralRe: Shared Data Problem Pin
sweep1235-May-04 3:41
sweep1235-May-04 3:41 
Generalvisual studio Pin
Mr. Cully4-May-04 5:25
Mr. Cully4-May-04 5:25 
GeneralRe: visual studio Pin
jmkhael4-May-04 5:27
jmkhael4-May-04 5:27 
GeneralRe: visual studio Pin
Mr. Cully4-May-04 5:43
Mr. Cully4-May-04 5:43 
Generalgetting the email address from an outlook _MailItem Pin
BlackDice4-May-04 5:10
BlackDice4-May-04 5:10 
GeneralRe: getting the email address from an outlook _MailItem Pin
Michael P Butler4-May-04 5:42
Michael P Butler4-May-04 5:42 
GeneralRe: getting the email address from an outlook _MailItem Pin
BlackDice4-May-04 6:29
BlackDice4-May-04 6:29 
Generaljpg to bmp Pin
Qualvis4-May-04 5:10
Qualvis4-May-04 5:10 

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.