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(LPCTSTR strDbFileName)
The definition in C#:
[DllImport("miniDataservice.dll", EntryPoint="NewDataBase",
SetLastError=true)]
public static extern bool NewDataBase(string FileName);
Thanks,
Ole 7 2144
HI,
saw the moment I pressed the send button: I forgot the charset option:
[DllImport("miniDataservice.dll", EntryPoint="NewDataBase",
SetLastError=true, CharSet = CharSet.Unicode)]
Now it works!
Thanks anyway,
Ole
"ORC" <or*@sol.dk> wrote in message
news:%2*****************@TK2MSFTNGP12.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(LPCTSTR strDbFileName)
The definition in C#: [DllImport("miniDataservice.dll", EntryPoint="NewDataBase", SetLastError=true)] public static extern bool NewDataBase(string 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(dllexport) 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="GetName",CharSet=CharSet.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("miniDataservice.dll", EntryPoint="NewDataBase", SetLastError=true, CharSet = CharSet.Unicode)]
Now it works!
Thanks anyway, Ole
"ORC" <or*@sol.dk> wrote in message news:%2*****************@TK2MSFTNGP12.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(LPCTSTR strDbFileName)
The definition in C#: [DllImport("miniDataservice.dll", EntryPoint="NewDataBase", SetLastError=true)] public static extern bool NewDataBase(string 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.
"GingerDeafMan" <gi*****************@yahoo.co.uk> wrote in message
news:MP************************@news.individual.ne t... 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(dllexport) 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="GetName",CharSet=CharSet.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("miniDataservice.dll", EntryPoint="NewDataBase", SetLastError=true, CharSet = CharSet.Unicode)]
Now it works!
Thanks anyway, Ole
"ORC" <or*@sol.dk> wrote in message news:%2*****************@TK2MSFTNGP12.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(LPCTSTR strDbFileName) > > The definition in C#: > [DllImport("miniDataservice.dll", EntryPoint="NewDataBase", > SetLastError=true)] > public static extern bool NewDataBase(string 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.NullReferenceException' 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.
"GingerDeafMan" <gi*****************@yahoo.co.uk> wrote in message news:MP************************@news.individual.ne t... 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(dllexport) 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="GetName",CharSet=CharSet.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.
"GingerDeafMan" <gi*****************@yahoo.co.uk> wrote in message
news:MP************************@news.individual.ne t... Hi Willy,
Thanks for this.
Have already tried CharSet.Ansi. Makes no difference.
The exception is
An unhandled exception of type 'System.NullReferenceException' 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.
"GingerDeafMan" <gi*****************@yahoo.co.uk> wrote in message news:MP************************@news.individual.ne t... > 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(dllexport) 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="GetName",CharSet=CharSet.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
GetManufacturerName(_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.
"GingerDeafMan" <gi*****************@yahoo.co.uk> wrote in message news:MP************************@news.individual.ne t... Hi Willy,
Thanks for this.
Have already tried CharSet.Ansi. Makes no difference.
The exception is
An unhandled exception of type 'System.NullReferenceException' 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.
"GingerDeafMan" <gi*****************@yahoo.co.uk> wrote in message news:MP************************@news.individual.ne t... > 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(dllexport) CALLBACK > void WINDLL GetName(LPCTSTR szMfr) > { > sprintf((char *)szMfr,"%s",A.Name);
GetManufacturerName(_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************************@news.individual.net> , gi*****************@yahoo.co.uk 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
GetManufacturerName(_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.
"GingerDeafMan" <gi*****************@yahoo.co.uk> wrote in message news:MP************************@news.individual.ne t... Hi Willy,
Thanks for this.
Have already tried CharSet.Ansi. Makes no difference.
The exception is
An unhandled exception of type 'System.NullReferenceException' 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,...
|
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...
|
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...
|
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...
|
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.
...
|
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...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
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...
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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...
|
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...
| |