|
MFC, STUDIO 2008,
Project use UNICODE
CString m_sTest;
m_sTest = L"Байкал";
char *m_pchar3;
m_pchar3 = new char[70];
How todo m_sTest into m_pchar3?
//- m_pchar3=m_sTest; // error C2440: '=' : cannot convert from 'CString' to 'char *'
//- strcpy(m_pchar3, m_sTest); // error C2664: 'strcpy' : cannot convert parameter 2 from 'CString' to 'const char *'
//- strcpy(m_pchar3, (TCHAR)m_sTest); // error C2440: 'type cast' : cannot convert from 'CString' to 'TCHAR'
//- _tcscpy( m_pchar3, (TCHAR*)(LPCTSTR)m_sTest ); // error C2664: 'wcscpy' : cannot convert parameter 1 from 'char *' to 'wchar_t *'
|
|
|
|
|
Why do you need to do that?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
CHIVOTIOV wrote: char *m_pchar3;
m_pchar3 = new char[70];
Use TCHAR instead of char .
|
|
|
|
|
The m_sTest is a UNICODE string. So if you want to convert this UNICODE string to char* use WideCharToMultiBye API or use CRT function wcstombs.
prvn
|
|
|
|
|
CHIVOTIOV wrote: / error C2664: 'wcscpy' : cannot convert parameter 1 from 'char *' to 'wchar_t *'
Just a padding to the other replies here. As the above lines says, You are trying to squeeze a 2 Byte string (UNICODE) into a single byte string(ANSI).
char , std::string , etc by default belong to the single byte representation.
wchar_t, std::wstring, etc represent UNICODE representation.
TCHAR is "neutral" based on the scheme used, it switches type accordingly. If you define # UNICODE in the setting, the string becomes 2 byte reps. If you don't define it, it becomes single byte. Also when you use TCHARs, you should use strings apis specific to TCHARs. (like _tcscpy) that assures complete independence to your character-set implementations.
Similarly, CString switches types based on the project character-set settings.(UNICODE/Single-byte).
Now you have defined UNICODE in your project settings but trying a cross-copy operation. So just figure out what needs to be done..
He never answers anyone who replies to him. I've taken to calling him a retard, which is not fair to retards everywhere.-Christian Graus
|
|
|
|
|
hi,
Can Anybody tell me how to write a list control data in text file in MFC?
|
|
|
|
|
CListCtrl has member functions like GetItem() , GetItemData() , etc., and there's CFile that you can use to write to file. Where exactly are you stuck?
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
Hi!
I have an array of pointers, which point to classes derived from the same class. I also have a pointer, that points to the array. Is there a simple way to find out to which element of the array this pointer points to, or shall i use a variable in the base class for this purpose?
Thanks
|
|
|
|
|
You may use RTTI [^].
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Actually, this solves another problem of mine, so thanks a lot However, I'd like to know, whether the pointer points to the 2nd, 5th, nth element of the array. If I understand the description correctly, type_info only gives me the name of the class my pointer-in-the-array points to (right?). First I thought of using sizof(), but my derived classes are of different sizes.
|
|
|
|
|
Please post the relevant code (I need to know the pointer relationship with the array).
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
I have a base class, let's say Car, and derived classes BMW, Mercedes, Renault, etc.
The array is: Car* p_Cars[2][16];
The pointer: Car** pCar;
for (int i = 0; i < 2; i++)
{
for (int j = 0; j < 16; j++)
{
if (j==2 || j==3)
p_Cars[i][j] = new BMW(i, j);
else if (j==4 || j==5)
p_Cars[i][j] = new Mercedes(i, j);
.
.
.
}
}
So I'd like to know, whether I can determine the element from its address.
I hope you understand my problem, i tried my best 
|
|
|
|
|
A given value of pCar refers to the element p_Cars[i][j] (i.e. pCar == &p_Cars[i][j] holds true), provided i,j are computed as follows:
int k = (int) (pCar - &p_Cars[0][0]);
int i = k / 16;
int j = k % 16;
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
|
You are welcome.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
So....you have:
CBase* pArray[] = { whatever... };
CBase* pItem = address_of_some_item_in_the_array; ?
In that case:
const size_t index = pItem - pArray;
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
|
Hi,
May i know how to check if a folder or file exists and if not create a folder....
im using ...
CString csPath1="C:\\Temp\\myfolder";
if(_access (csPath1+_T("\\Test"), 0)==-1);
::CreateDirectoryW(csPath1+L"\\Test",NULL);
and im getting the below error....
'_access' :cannot convert parameter 1 from 'ATL::CStringT<BaseType,StringTraits>' to 'const char *'...
Please help me......(myproject is in unicode)
|
|
|
|
|
Why do you need to check first?
CreateDirectory will return ERROR_ALREADY_EXISTS if the directory already exists.
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
Thanks for ur help and please let me know how can i check whether a file(not directory) exists....(my project is in unicode)........
|
|
|
|
|
You can use PathFileExists()[^] function (works with both folders and files).
The page contains a sample as well - saves me from typing code. Do remember to include shlwapi.h and link to shlwapi.lib .
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
How can I use DLL file in C#.NET ? I create dll in Borland C++ Compiler 5.5.1 and using C language.
Following code is not work.
My C Code;
-----------------------------------------------------
//hello.dll
#include <windows.h>
extern "C"
{
void __declspec (dllexport) function1()
{
MessageBox (NULL, "test message","test title",0);
}
}
BOOL WINAPI DllMain (HINSTANCE, DWORD, LPVOID)
{
return TRUE;
}
My C# Code;
-----------------------------------------------------
[DllImport("C:\hello.dll")]
public static extern void function1();
private void button1_Click(object sender, EventArgs e)
{
function1();
}
|
|
|
|
|
Ok, I try this; But I get this error: Entry Point Not Found
C DLL CODE
-----------------------------------------------
#include <windows.h>
BOOL __stdcall DllMain(HINSTANCE hInst, DWORD dwReason, LPVOID lpReserved) {
return TRUE;
}
__declspec(dllexport) void __stdcall Message(char* p_szMessage) {
MessageBox(NULL, p_szMessage, "Message from DLL", MB_OK);
}
C# DLL CODE
-----------------------------------------------
[DllImport("filename.dll")]
static extern void Message(string msg);
private void button1_Click(object sender, EventArgs e)
{
Message("Hello world");
}
|
|
|
|
|
What does it mean, specifically, 'it doesn't work' (i.e. more details needed)?
BTW you possibly would get better help at C# forum.
BTW2: I saw you've already cross-posted your question...
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
cross-posted is forbidden? Because this question related about between c and c#.
How can I "dumpbin -exports dll" in borland c++ 5.5.1 compiler on command prompt?
Do you have any idea?
|
|
|
|