Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++/CLI
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 29-Dec-09 12:42pm
denisut150
Edited 3-Jan-10 3:55am
v3
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

The code you posted is not valid C++ (or any other language I am familiar with). For instance:
 
free(wchar_t);
 
is illegal.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

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!!!!
...
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

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]
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

Sorry to evrybody. I typed here with mistake not free(wchar_t), but free(WString). But question still the same.
  Permalink  
v4

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

  Print Answers RSS
0 OriginalGriff 495
1 Maciej Los 340
2 Richard MacCutchan 265
3 BillWoodruff 225
4 Mathew Soji 200
0 OriginalGriff 8,804
1 Sergey Alexandrovich Kryukov 7,457
2 DamithSL 5,689
3 Maciej Los 5,279
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web02 | 2.8.1411028.1 | Last Updated 3 Jan 2010
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100