473,387 Members | 1,757 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,387 software developers and data experts.

String support under managed vc

Hello,
I have an old project written in c++ that also uses MFC.
It's a class that allows me to access a data base, it does not export
any MFC interfaces it's a "simple" c++ class that uses several
capabilities of MFC.

I want to use it in a c# application, that is why I decided to create a
proxy in managed c++.
1. I created a CLR Console Application.
2. I added my class files.
3. I chose under properties/configuration properties/Use of MFC - Use
MFC in a shared DLL.

I have the following definitions:
bool ResultSet::BindUni(int col_no,unsigned short* buff,int len) {
....
}
....
TCHAR szOLWord[500];
....
rslt.BindUni(1,szOLWord,500);

On the last line I receive an error :
Error 19 error C2664: 'ResultSet::BindUni' : cannot convert parameter 2
from 'TCHAR [500]' to 'unsigned short *

I can compile the above files under VC++ 6:
1. I'm using the Unicode version of the MFC libraries.
2. I'm using _UNICODE preprocess definition.

Any ideas on how to solve it?

Thank you,
Efi

Sep 26 '06 #1
3 1129

fo****@gmail.com a écrit :
Hello,

I have the following definitions:
bool ResultSet::BindUni(int col_no,unsigned short* buff,int len) {
...
}
...
TCHAR szOLWord[500];
...
rslt.BindUni(1,szOLWord,500);

On the last line I receive an error :
Error 19 error C2664: 'ResultSet::BindUni' : cannot convert parameter 2
from 'TCHAR [500]' to 'unsigned short *

I can compile the above files under VC++ 6:
1. I'm using the Unicode version of the MFC libraries.
2. I'm using _UNICODE preprocess definition.

Any ideas on how to solve it?
Under VC6, wchar_t (which is the meaning of TCHAR when _UNICODE is
defined) was a typedef for short. But this was just a workaround for
the fact that VC6 didn't support wchar_t has a built-in type.

VC2005 is more compliant and supports wchar_t as a built-in type :
therefore, you cannot replace a wchar_t by a short, or vice-versa
(they are different things, aimed at different goals!)

Your code is non standard-compliant, and it was a shortcoming of VC6
that it accepted to compile it. Either define szOLWord as an array of
short, either change the signature of BindUni so that it takes a
wchar_t* for it's "buf" parameter. I can't say which one is correct
since I don't know what your code does.

Arnaud
MVP - VC

Sep 27 '06 #2
Thank you.

For some unknown reason I thought that porting a c++ code from vc 6 to
vc .net will be easy.
ad******@club-internet.fr כתב:
fo****@gmail.com a écrit :
Hello,

I have the following definitions:
bool ResultSet::BindUni(int col_no,unsigned short* buff,int len) {
...
}
...
TCHAR szOLWord[500];
...
rslt.BindUni(1,szOLWord,500);

On the last line I receive an error :
Error 19 error C2664: 'ResultSet::BindUni' : cannot convert parameter 2
from 'TCHAR [500]' to 'unsigned short *

I can compile the above files under VC++ 6:
1. I'm using the Unicode version of the MFC libraries.
2. I'm using _UNICODE preprocess definition.

Any ideas on how to solve it?

Under VC6, wchar_t (which is the meaning of TCHAR when _UNICODE is
defined) was a typedef for short. But this was just a workaround for
the fact that VC6 didn't support wchar_t has a built-in type.

VC2005 is more compliant and supports wchar_t as a built-in type :
therefore, you cannot replace a wchar_t by a short, or vice-versa
(they are different things, aimed at different goals!)

Your code is non standard-compliant, and it was a shortcoming of VC6
that it accepted to compile it. Either define szOLWord as an array of
short, either change the signature of BindUni so that it takes a
wchar_t* for it's "buf" parameter. I can't say which one is correct
since I don't know what your code does.

Arnaud
MVP - VC
Sep 27 '06 #3

<fo****@gmail.coma écrit dans le message de news:
11**********************@i42g2000cwa.googlegroups. com...
Thank you.

For some unknown reason I thought that porting a c++ code from vc 6 to
vc .net will be easy.
Porting *standard* code from VC6 to VC2005 is quite easy. The problem is
that VC6 allowed you to write non-standard (ie, buggy) code ;-)

Arnaud
MVP - VC
Sep 27 '06 #4

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

Similar topics

1
by: Steven Blair | last post by:
Hi, I am having problem passing a string by reference to some C++ code. Wondered if anyone could help me out. C# code: myFunc(str);
60
by: Julie | last post by:
What is the *fastest* way in .NET to search large on-disk text files (100+ MB) for a given string. The files are unindexed and unsorted, and for the purposes of my immediate requirements, can't...
10
by: Bonj | last post by:
I use the following code to convert a managed string to an unmanaged one: _TCHAR error; const char* umstring = (const char*)Marshal::StringToHGlobalAnsi (merror).ToPointer(); _tcscpy(error,...
8
by: tbh | last post by:
for historical reasons i need to be able to call, from C# under DotNet 2, as COM+ DLL function that returns a "string" which is really an array of seemingly arbitrary bytes (presumably non-zero)....
15
by: =?Utf-8?B?TWFkcyBOaWVsc2Vu?= | last post by:
Hi, I am developing a web service for a customer. The service has a method, that returns an array of Forms. Each form has a Name property of Type String. The customer wants the contract to...
4
by: Peter Larsen [] | last post by:
Hi, How do i read a resource string from a dll in code ?? BR Peter
3
by: =?Utf-8?B?c2lwcHl1Y29ubg==?= | last post by:
Hi I have an xsd that I want to save as an XML string to store in a DB I can save as a physical file using xsd.WriteXml(@"C:\Temp\Junk\junk.xml"); But I am unable to save to a string so I...
2
by: =?Utf-8?B?c2lwcHl1Y29ubg==?= | last post by:
Hi Is there any way to Read an INIFile from a string or Stream instead of a physical file ??? I want to read the INIFile into a string then store in a db but when I read the string from the...
8
by: Brett | last post by:
I wrote an ASP.NET application that queries a SQL Server database (on a different box from the web server) and displays the result in a GridView. The datasource for the GridView is a SQLDataSource....
2
by: Bill McCormick | last post by:
Hi, I'm building a C# VS2005 project and I need an elegant way to output query results to an string array or list<Tof delimited strings. Thanks, Bill
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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:
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
Oralloy
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,...
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...

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.