String support under managed vc

F

fooshm

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
 
A

adebaene

(e-mail address removed) 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
 
F

fooshm

Thank you.

For some unknown reason I thought that porting a c++ code from vc 6 to
vc .net will be easy.


(e-mail address removed) כתב:
(e-mail address removed) 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
 
A

Arnaud Debaene

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top