473,396 Members | 1,770 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

how to pass char * from C++ into c# method

I have this c# interface:
int EditActuateConfigFile([In, MarshalAs(UnmanagedType.LPStr)] string s);

and I call it from C++ with a char * - it compiles, at runtime there is no
complaint, but I put logging in the method and it isn't being called.

If I have an int argument or no arguments, the logging occurs.

I am writing a C++ Custom Action for an MSI install and have a C# DLL with
methods I need to call ...

// Class1.cs
// A simple managed DLL that contains a method to add two numbers.
using System;
using System.IO;
using System.Configuration;
using System.Diagnostics;
using System.Runtime.InteropServices;

using log4net;
using log4net.Config;
[assembly: log4net.Config.XmlConfigurator()]

namespace ManagedDLL
{
// Interface declaration.
public interface IConfigureActuateXml
{
int Edit();
int EditActuateConfigFile([In, MarshalAs(UnmanagedType.LPStr)] string s);
};

// Interface implementation.
public class ManagedClass:IConfigureActuateXml
{
private static readonly ILog log = LogManager.GetLogger("ManagedClass");
public int EditActuateConfigFile()
{
log4net.Config.XmlConfigurator.ConfigureAndWatch(n ew
FileInfo("/tmp/owen.config"));
log.Info("In EditActuateConfigFile, s = " + s);
return 0;
}
public int Edit()
{
log4net.Config.XmlConfigurator.ConfigureAndWatch(n ew
FileInfo("/tmp/owen.config"));
log.Info("In Edit");
return 1;
}
}
}
The C++ calling it (if I call edit() everything works):

long status = 0;
char *tempDirName;
status = getTempDir(hInstall, tempDirName);
if (status != ERROR_SUCCESS) return status;

// Create the interface pointer.
IConfigureActuateXmlPtr pIConfig(__uuidof(ManagedClass));
long lResult;

pIConfig->EditActuateConfigFile(tempDirName, &lResult);
fprintf(fp, "returned from calling EditActuateConfigFile. lResult = %ld\n",
lResult);

Nov 17 '05 #1
0 2159

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: dumboo | last post by:
hi there i m little bit confused over the following problem, i have understood wt the following code is doing...but not able to get the actual techinical stuff.....i have had a lot of hot debate...
11
by: lokb | last post by:
Hi, I have a structure which and defined a smart pointer to the structure. /* Structure of Begin Document Index Record */ typedef struct BDI_Struct{ unsigned char rname; unsigned short int...
8
by: Ekim | last post by:
my question is as follows: I've got a DLL in which I have a method GetBuffer (this one is extern, exported, is called from outside this program) which shall pass a char-buffer to the...
9
by: ceo | last post by:
Hi there, I'm reffering to a text that says following: "To summarize: When a copy of an object is generated because it passed to a function, the object's constructor function is not called....
2
by: seamoon | last post by:
ENG> How can I pass a value through CREATESTRUCT in MDI applications? How can I pass a parameter to CREATESTRUCT in VC++ MDI application. For example, Dialogue based examples can pass a value to...
16
by: Ekim | last post by:
hello, I'm allocating a byte-Array in C# with byte byteArray = new byte; Now I want to pass this byte-Array to a managed C++-function by reference, so that I'm able to change the content of the...
7
by: SB | last post by:
What is the proper way to pass a character array (char *) from a "C" dll to a C# method (delegate) in my app? Getting the dll (which simulates a third party dll) to call my delegate works fine. ...
4
by: CsharpGuy | last post by:
I took over an web app (C#) were the developer put everything in a has table then called a method to execute a stored procedure, now I'm running into some issues were if I do an update and a NULL...
3
by: Prabu Ramasamy | last post by:
how to pass char* value by creating new? here function definition is ConvertNumberToString(double source, char *targetString) { } wil u pleas tell me how to pass (char* targetstring)...
29
by: Kenzogio | last post by:
Hi, I have a struct "allmsg" and him member : unsigned char card_number; //16 allmsg.card_number
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.