Click here to Skip to main content
15,895,192 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have Window 2008 Server 64 bit. Under this OS running 32 bit application(written not by me). I wrote dll library wich i use with this application. In this dll library i have external function that must return wchar_t*. Under Windows 32 bit it works good but under
Windows 64 bit not.

Example:
// Part of code
...
//declare
static wchar_t* WString = L"Test text";
...

//function
static wchar_t * ConvertStringToWString(const char* Value){
  try{
     free(WString);
     size_t converted = 0;
     size_t memlength = (strlen(Value)+1) * (sizeof(wchar_t));
     WString = (wchar_t*)malloc(memlength);	
     mbstowcs_s(&converted,WString,memlength,Value,((size_t)-1));
     return WString;
  }   
  finally{
    delete Value;
  }
}
//End


Any ideas?
Posted
Updated 3-Jan-10 2:55am
v3

The code you posted is not valid C++ (or any other language I am familiar with). For instance:

free(wchar_t);


is illegal.
 
Share this answer
 
This line :
free(wchar_t);

Doesn't look quite right to me.

The use of malloc and free on a static pointer is not advisable as well. You should either malloc a new array in the body of the function and make the caller resposible for calling free on it, or require the caller to provide a buffer to use for the new wchar_t string.

Also I notice you are mixing delete and free. This is a very unsafe practice. You should pick one method (either malloc/free or new/delete) and stick with it.
 
Share this answer
 
I have Windows 2008 Server 64 bit. Under this OS running 32 bit application(NB!!!!!written not by me). This application(AspicMP - http://shop.kontron-czech.com/DetailPage.asp?DPG=69698") give me oportunity to extend it functionality by connectig dll's and externig it functions. I cannot control pointers(deleting) or making any mainpulations with addresses of pointers.This application has it own restrictions.
...
Under Windows 32 bit this application works with my dll perfectly without any problem!!!!
...
 
Share this answer
 
You wrote:
Under Windows 32 bit this application works with my dll perfectly without any problem!!!!


This is not possible as the code you posted above will not compile. The statement free(wchar_t); as mentioned below is illegal in C/C++.

[edit]Removed confusing/ed statement[/edit]
 
Share this answer
 
v2
Sorry to evrybody. I typed here with mistake not free(wchar_t), but free(WString). But question still the same.
 
Share this answer
 
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900