Hi,
How to transfer strings between a C# .NET application and a native DLL that
uses Unicode like:
#ifndef UNICODE
#define UNICODE
#endif
The function header in the DLL:
BOOL NewDataBase(LPC TSTR strDbFileName)
The definition in C#:
[DllImport("mini Dataservice.dll ", EntryPoint="New DataBase",
SetLastError=tr ue)]
public static extern bool NewDataBase(str ing FileName);
Thanks,
Ole 7 2172
HI,
saw the moment I pressed the send button: I forgot the charset option:
[DllImport("mini Dataservice.dll ", EntryPoint="New DataBase",
SetLastError=tr ue, CharSet = CharSet.Unicode )]
Now it works!
Thanks anyway,
Ole
"ORC" <or*@sol.dk> wrote in message
news:%2******** *********@TK2MS FTNGP12.phx.gbl ... Hi,
How to transfer strings between a C# .NET application and a native DLL
that uses Unicode like: #ifndef UNICODE #define UNICODE #endif
The function header in the DLL: BOOL NewDataBase(LPC TSTR strDbFileName)
The definition in C#: [DllImport("mini Dataservice.dll ", EntryPoint="New DataBase", SetLastError=tr ue)] public static extern bool NewDataBase(str ing FileName);
Thanks, Ole
Hi Ole and the rest,
Have just subscribed to this NG and found this. I have a similar
problem.
I am trying to get a function in C++ DLL to return a string.
Code in DLL is (a portion)
#define WINDLL __declspec(dlle xport) CALLBACK
void WINDLL GetName(LPCTSTR szMfr)
{
sprintf((char *)szMfr,"%s",A. Name);
}
"Name" is char array.
Code in C# is
[DllImport("C:\\ MyDLL.DLL",
EntryPoint="Get Name",CharSet=C harSet.Auto)]
private static extern void GetName(string strName);
This throws an exception
string strName;
GetName(strName );
I am stuck here, obviously. Any ideas as what I am doing wrong, or
alternative methods for passing char arrays back from the DLL to C# as a
string would be welcome.
TIA,
Cheers,
Paul.
In article <u6************ **@TK2MSFTNGP12 .phx.gbl>, or*@sol.dk says... HI, saw the moment I pressed the send button: I forgot the charset option: [DllImport("mini Dataservice.dll ", EntryPoint="New DataBase", SetLastError=tr ue, CharSet = CharSet.Unicode )]
Now it works!
Thanks anyway, Ole
"ORC" <or*@sol.dk> wrote in message news:%2******** *********@TK2MS FTNGP12.phx.gbl ... Hi,
How to transfer strings between a C# .NET application and a native DLL that uses Unicode like: #ifndef UNICODE #define UNICODE #endif
The function header in the DLL: BOOL NewDataBase(LPC TSTR strDbFileName)
The definition in C#: [DllImport("mini Dataservice.dll ", EntryPoint="New DataBase", SetLastError=tr ue)] public static extern bool NewDataBase(str ing FileName);
Thanks, Ole
What exception?
Your function is expecting an ANSI string, so you should use CharSet.Ansi
And you don't return anything.
Willy.
"GingerDeaf Man" <gi************ *****@yahoo.co. uk> wrote in message
news:MP******** *************** *@news.individu al.net... Hi Ole and the rest,
Have just subscribed to this NG and found this. I have a similar problem.
I am trying to get a function in C++ DLL to return a string.
Code in DLL is (a portion)
#define WINDLL __declspec(dlle xport) CALLBACK void WINDLL GetName(LPCTSTR szMfr) { sprintf((char *)szMfr,"%s",A. Name); }
"Name" is char array.
Code in C# is
[DllImport("C:\\ MyDLL.DLL", EntryPoint="Get Name",CharSet=C harSet.Auto)] private static extern void GetName(string strName);
This throws an exception
string strName; GetName(strName );
I am stuck here, obviously. Any ideas as what I am doing wrong, or alternative methods for passing char arrays back from the DLL to C# as a string would be welcome.
TIA,
Cheers,
Paul.
In article <u6************ **@TK2MSFTNGP12 .phx.gbl>, or*@sol.dk says... HI, saw the moment I pressed the send button: I forgot the charset option: [DllImport("mini Dataservice.dll ", EntryPoint="New DataBase", SetLastError=tr ue, CharSet = CharSet.Unicode )]
Now it works!
Thanks anyway, Ole
"ORC" <or*@sol.dk> wrote in message news:%2******** *********@TK2MS FTNGP12.phx.gbl ... > Hi, > > How to transfer strings between a C# .NET application and a native DLL that > uses Unicode like: > #ifndef UNICODE > #define UNICODE > #endif > > The function header in the DLL: > BOOL NewDataBase(LPC TSTR strDbFileName) > > The definition in C#: > [DllImport("mini Dataservice.dll ", EntryPoint="New DataBase", > SetLastError=tr ue)] > public static extern bool NewDataBase(str ing FileName); > > Thanks, > Ole > >
Hi Willy,
Thanks for this.
Have already tried CharSet.Ansi. Makes no difference.
The exception is
An unhandled exception of type 'System.NullRef erenceException ' occurred
in nch.dll
Additional information: Object reference not set to an instance of an
object
Paul.
In article <Oh************ **@TK2MSFTNGP09 .phx.gbl>, wi************* @pandora.be says... What exception? Your function is expecting an ANSI string, so you should use CharSet.Ansi And you don't return anything.
Willy.
"GingerDeaf Man" <gi************ *****@yahoo.co. uk> wrote in message news:MP******** *************** *@news.individu al.net... Hi Ole and the rest,
Have just subscribed to this NG and found this. I have a similar problem.
I am trying to get a function in C++ DLL to return a string.
Code in DLL is (a portion)
#define WINDLL __declspec(dlle xport) CALLBACK void WINDLL GetName(LPCTSTR szMfr) { sprintf((char *)szMfr,"%s",A. Name); }
"Name" is char array.
Code in C# is
[DllImport("C:\\ MyDLL.DLL", EntryPoint="Get Name",CharSet=C harSet.Auto)] private static extern void GetName(string strName);
This throws an exception
string strName; GetName(strName );
I am stuck here, obviously. Any ideas as what I am doing wrong, or alternative methods for passing char arrays back from the DLL to C# as a string would be welcome.
TIA,
Cheers,
Paul.
In article <u6************ **@TK2MSFTNGP12 .phx.gbl>, or*@sol.dk says... HI, saw the moment I pressed the send button: I forgot the charset option:
But what is nch.dll?
Your exception is a managed exception indicating a null reference usage.
Need some more code to investigate the problem, please post at least the
code part surrounding the intruction/call that throws.
Also when you intend to pass and return a char* you should pass a
StringBuilder instead of a String
Willy.
"GingerDeaf Man" <gi************ *****@yahoo.co. uk> wrote in message
news:MP******** *************** *@news.individu al.net... Hi Willy,
Thanks for this.
Have already tried CharSet.Ansi. Makes no difference.
The exception is
An unhandled exception of type 'System.NullRef erenceException ' occurred in nch.dll
Additional information: Object reference not set to an instance of an object
Paul.
In article <Oh************ **@TK2MSFTNGP09 .phx.gbl>, wi************* @pandora.be says... What exception? Your function is expecting an ANSI string, so you should use CharSet.Ansi And you don't return anything.
Willy.
"GingerDeaf Man" <gi************ *****@yahoo.co. uk> wrote in message news:MP******** *************** *@news.individu al.net... > Hi Ole and the rest, > > Have just subscribed to this NG and found this. I have a similar > problem. > > I am trying to get a function in C++ DLL to return a string. > > Code in DLL is (a portion) > > #define WINDLL __declspec(dlle xport) CALLBACK > void WINDLL GetName(LPCTSTR szMfr) > { > sprintf((char *)szMfr,"%s",A. Name); > } > > "Name" is char array. > > Code in C# is > > [DllImport("C:\\ MyDLL.DLL", > EntryPoint="Get Name",CharSet=C harSet.Auto)] > private static extern void GetName(string strName); > > This throws an exception > > string strName; > GetName(strName ); > > I am stuck here, obviously. Any ideas as what I am doing wrong, or > alternative methods for passing char arrays back from the DLL to C# as > a > string would be welcome. > > TIA, > > Cheers, > > Paul. > > > In article <u6************ **@TK2MSFTNGP12 .phx.gbl>, or*@sol.dk says... >> HI, >> saw the moment I pressed the send button: I forgot the charset >> option:
nch.dll should have been mydll.dll. They are one and the same. I
simply forgot to rename nch.dll to mydll.dll to match the earlier
posting.
The code that causes the exception is this line
GetManufacturer Name(_Name);
_Name is a string.
I am not sure what "null reference usage" means.
Ta for the tip re StringBuilder. Will investigate this.
Paul.
In article <Of************ **@TK2MSFTNGP10 .phx.gbl>, wi************* @pandora.be says... But what is nch.dll? Your exception is a managed exception indicating a null reference usage. Need some more code to investigate the problem, please post at least the code part surrounding the intruction/call that throws. Also when you intend to pass and return a char* you should pass a StringBuilder instead of a String Willy.
"GingerDeaf Man" <gi************ *****@yahoo.co. uk> wrote in message news:MP******** *************** *@news.individu al.net... Hi Willy,
Thanks for this.
Have already tried CharSet.Ansi. Makes no difference.
The exception is
An unhandled exception of type 'System.NullRef erenceException ' occurred in nch.dll
Additional information: Object reference not set to an instance of an object
Paul.
In article <Oh************ **@TK2MSFTNGP09 .phx.gbl>, wi************* @pandora.be says... What exception? Your function is expecting an ANSI string, so you should use CharSet.Ansi And you don't return anything.
Willy.
"GingerDeaf Man" <gi************ *****@yahoo.co. uk> wrote in message news:MP******** *************** *@news.individu al.net... > Hi Ole and the rest, > > Have just subscribed to this NG and found this. I have a similar > problem. > > I am trying to get a function in C++ DLL to return a string. > > Code in DLL is (a portion) > > #define WINDLL __declspec(dlle xport) CALLBACK > void WINDLL GetName(LPCTSTR szMfr) > { > sprintf((char *)szMfr,"%s",A. Name);
GetManufacturer Name(_Name) should have been GetName(strName ), to follow
the earlier example. Today is definitely not one of my better days :O
But I think we are getting the idea.
GetName(strName ) is throwing the exception and I don't know what to do
about this.
Have just tried StringBuilder but still this makes no difference (same
exception thrown).
Paul.
In article <MP************ ************@ne ws.individual.n et>, gi************* ****@yahoo.co.u k says... nch.dll should have been mydll.dll. They are one and the same. I simply forgot to rename nch.dll to mydll.dll to match the earlier posting.
The code that causes the exception is this line
GetManufacturer Name(_Name);
_Name is a string.
I am not sure what "null reference usage" means.
Ta for the tip re StringBuilder. Will investigate this.
Paul.
In article <Of************ **@TK2MSFTNGP10 .phx.gbl>, wi************* @pandora.be says... But what is nch.dll? Your exception is a managed exception indicating a null reference usage. Need some more code to investigate the problem, please post at least the code part surrounding the intruction/call that throws. Also when you intend to pass and return a char* you should pass a StringBuilder instead of a String Willy.
"GingerDeaf Man" <gi************ *****@yahoo.co. uk> wrote in message news:MP******** *************** *@news.individu al.net... Hi Willy,
Thanks for this.
Have already tried CharSet.Ansi. Makes no difference.
The exception is
An unhandled exception of type 'System.NullRef erenceException ' occurred in nch.dll
Additional information: Object reference not set to an instance of an object
Paul.
In article <Oh************ **@TK2MSFTNGP09 .phx.gbl>, wi************* @pandora.be says... > What exception? > Your function is expecting an ANSI string, so you should use CharSet.Ansi This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: gabor |
last post by:
hi,
today i made some tests...
i tested some unicode symbols, that are above the 16bit limit
(gothic:http://www.unicode.org/charts/PDF/U10330.pdf)
..
i played around with iconv and so on,
so at the end i created an utf8 encoded text file,
|
by: Michael Foord |
last post by:
I'm trying to become 'unicode-aware'... *sigh*. What's that quote - 'a
native speaker of ascii will never learn to speak unicode like a
native'. The trouble is I think I've been a native speaker of latin-1
without realising it.
My main problem with udnerstanding unicode is what to do with
arbitrary text without an encoding specified. To the best of my
knowledge the technical term for this situation is 'buggered'. E.g. I
have a CGI...
|
by: Sunil Jain |
last post by:
I am having trouble displaying unicode characters on the
browser.
I am storing unicode data (Japanese, Chinese and Korean)
in the native format. I have an ASP page that runs a query
to get this data and display it on my webpage. But, the
output comes as junk.
Any solutions for that.
|
by: srikant |
last post by:
I am writing a client in C# that needs to communicate over the network to a legacy C++ application that uses Unicode strings. I realize that C# strings are already in Unicode, however, how do I account for the network order transformation. Can I simply do the equivalent of
string = "hello world"; // this is a unicode strings (2 bytes per char)
bytes buffer = UnicodeEncoding.GetBytes(str);
myNetworkStream.Write(buffer, 0, buffer.Length);
...
|
by: Nir Aides |
last post by:
Hello,
Is there a solution or a work around for the sys.path problem with
unicode folder names on Windows XP?
I need to be able to import modules from a folder with a non-ascii name.
Thanks,
Nir
| |
by: Tomás |
last post by:
Let's start off with:
class Nation {
public:
virtual const char* GetName() const = 0;
}
class Norway : public Nation {
public:
virtual const char* GetName() const
|
by: starffly |
last post by:
I want to read a xml file in Unicode, UTF-8 or a native encoding
into a wchar_t type string, so i write a routine as follows, however,
sometimes a Unicode file including Chinese character cannot be read
completely. and I cannot tell where its root located, so NEED your
help, GIVE me a hand please.
THX.
static Status LoadXMLFile2String(const char *filename, wchar_t *text){
FILE *f;
if(!(f = fopen(filename, "r"))){
__printDebugA("Input...
|
by: Barry |
last post by:
Hi group,
As I found out
Boost has utf8_codecvt_facet
So is there any library completely support for all UTF in this way
or any other way to deal with Unicode more elegantly?
How ICU supports C++ io stream?
|
by: KK |
last post by:
Hello all,
There could be flavors of this question discussed in the past, but I
could not really make a head/tail out of it.
I have bunch of unicode values stored in a string array and I want to
see the corresponding characters displayed in an excel file. How could
I go about doing that ?
vector<stringunicodevalues; // has values 0041, 0042, ... 0410 etc.
(hexa decimal values)
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |