Hi,
I want to use a dll, that is written in C#, in my VS 6 C++ console application. Unfortunatly I can not find any way
Is it possible to use it
thanks..
Hi,
I want to use a dll, that is written in C#, in my VS 6 C++ console application. Unfortunatly I can not find any way
Is it possible to use it
thanks..
How to use .Net assembly in VS 6 C++ Project ?
Wainz
Thank you for your response , it helps alot. I can implement the the sample. But it does not work on my dll,
My C# dll is for MSMQ operations .I can send messages to MSMQ in a C# application by using this dll(after modification that is explained in your link) and same function order. But it does not work with C++. In debug mode , Insatance can be created but while calling SendMSMQMsg function I get the following error
Debug Error'
Program:.. CDLL.exe
Module :
File :i386\chkesp.c
Line:42
The value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one calling converition with a function pointer declared with a differenr called convertion
Stop: Retry Ignore
And no message can be sent to MSMQ
Threre is no error in release and no message can be sent to MSMQ. I hav not seen a sample dll that contains class members as my dll. The only have functions. Can it cause it
C++ and C# code segments can be seen below.
/////////////// C++ /////////////////
#include "stdafx.h"
#include <windows.h>
#include <stdio.h>
#pragma warning (disable: 4278)
// To use managed-code servers like the C# server,
// we have to import the common language runtime:
#import "mscorlib.tlb" raw_interfaces_only
#import "lib_msmq.tlb" no_namespace named_guids
//#endif
int main(int argc, char* argv[])
{
ILib_msmq *cpi = NULL;
int retval = 1;
// Initialize COM and create an instance of the InterfaceImplementation class:
CoInitialize(NULL);
HRESULT hr = CoCreateInstance(CLSID_Lib_msmq,
NULL, CLSCTX_INPROC_SERVER,
IID_ILib_msmq, reinterpret_cast<void**>(&cpi));
if (FAILED(hr))
{
printf("Couldn't create the instance!... 0x%x\n", hr);
}
else
{
printf("Calling function.\n");
fflush(stdout);
// The variable cpi now holds an interface pointer
// to the managed interface.
// If you are on an OS that uses ASCII characters at the
// command prompt, notice that the ASCII characters are
// automatically marshaled to Unicode for the C# code.
int aa;
cpi->SetQueue("1crd1");
aa = cpi->SendMSMQMsg("dene","data");
printf("Returned from function.\n");
cpi->Release();
cpi = NULL;
}
// Be a good citizen and clean up COM:
CoUninitialize();
return retval;
}
/////////////// Some Code segment from C# DLL /////////////////
using System;
using System.Messaging;
using System.Runtime.InteropServices;
namespace libmsmq
{
[Guid("D6F88E95-8A27-4ae6-B6DE-0542A0FC7039")]
public interface ILib_msmq
{
void SetQueue(string pi_queueName);
void SetMSMQMsg(string msg_label,string msg_body);
int SendMSMQMsg(string msg_label, string msg_body);
void KillEmAll();
}
/// <summary>
/// Summary description for Class1.
/// </summary>
[Guid("13FE32AD-4BF8-495f-AB4D-6C61BD463EA4")]
public class Lib_msmq : ILib_msmq
{
private MessageQueue monitorQueue;
private Message monitor_msg;
private MessagePropertyFilter filtre;
////////////////////
public void SetQueue(string pi_queueName)
{
monitor_msg= new Message();
monitorQueue = new MessageQueue( @".\PRIVATE$\"+ pi_queueName);
filtre= new MessagePropertyFilter();
filtre.SetAll();
monitorQueue.MessageReadPropertyFilter=filtre;
}
///////////////////////////////////
public int SendMSMQMsg(string msg_label, string msg_body)
{
try
{
monitor_msg.Body=msg_body;
monitor_msg.Label=msg_label;
SendMSMQMsg();
return MSMQ_SUCCESS;
}
catch(Exception e)
{
errorStr=e.Message;
return MSMQ_ERROR;
}
}
Alexei_shk