473,396 Members | 1,748 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.

String to WCHAR* conversion

Hello

I am trying to call a C++ DLL from C#:

C# code:
[DllImport("Log")]
static extern void LogMsg(String wsString1);
static void Main(string[] args)
{
LogMsg("Works!");
}

C++ DLL:
__declspec(dllexport) ULONG LogMsg(WCHAR* wsString1)
{

}

The problem is that the wsString1 from C# is being converted to a
garbage message.
Can some one help me on this conversion from C# string to WCHAR*.

I read somewhere that C# string is converted to LPTSTR in C++.
So, I even tried:

__declspec(dllexport) ULONG LogMsgNew(LPTSTR lpString1)
{
LogMsg(T2W(lpString1));
}
Any help is greatly appreciated. Thanks in advance
Jan 4 '08 #1
1 11232
Thanks to MSDN:

[DllImport("Log")]
static extern void LogMsg([MarshalAs(UnmanagedType.LPWStr)]String
wsString1);
Jan 4 '08 #2

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

Similar topics

12
by: Flzw | last post by:
How to convert a std::string to a WCHAR* ? is there any methods or something ? I can't find. Thanks
3
by: Lars Nielsen | last post by:
Hey there I have a win32 application written i c++. I have a std::vector of std::string's i will fill with filenames. typedef vector<std::string> strvector; strvector vFiles; ...
1
by: Kieran Benton | last post by:
Hi, Sorry to post this, I feel like a right fool but Im under serious time pressure! Afraid I'm a newbie to managed C++ (Ive had to resort to it as Im wrapping some COM objects for C# use). Any...
5
by: Lonewolf | last post by:
Hi, I'm not sure if this has been asked before so please pardon me if this is a repeated question. Basically I have some performance critical directshow codes which is implemented in native,...
14
by: Lindsay | last post by:
I need a string to be shared between all instances of my dll. Also, I need to append the string with each new instance of the dll. The string is declared: #pragma bss_seg("MYBSS") WCHAR*...
3
by: devrobcom | last post by:
Anyone knowing a better way of creating a format string than this? WCHAR sw_arg; int val1, val2; WCHAR mstring; WCHAR inbuffer1 = L"-value1 100 -value2 1000 -string1 mystring\t"; int read_no2;...
14
by: rohitpatel9999 | last post by:
Hi While developing any software, developer need to think about it's possible enhancement for international usage and considering UNICODE. I have read many nice articles/items in advanced C++...
1
by: AvinashS | last post by:
I have a WCHAR array (say WCHAR *wszName). I want to convert it to wstring. So, I do the following:- wstring wstrName(wszName); It works. But I want to know what internally happens when the...
18
by: Manjunath.M | last post by:
Hi, I wrote a simple program. WCHAR NameBuffer; char * str1 = "c:\\Program Files\\test.txt" ; swprintf(NameBuffer,L"%s",str1); I tried to debug this program. value at "Namebuffer" is...
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: 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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.