在64位操作系统下获取wchar_t *的问题 [英] Problem of getting wchar_t* under 64 bit OS

查看:275
本文介绍了在64位操作系统下获取wchar_t *的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有Windows 2008 Server 64位.在这个操作系统下运行32位应用程序(不是我写的).我编写了与此应用程序一起使用的dll库.在这个dll库中,我具有必须返回wchar_t *的外部函数.在Windows 32位元下,它运作良好,但在
下 Windows 64位不.

示例:

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?

推荐答案

您发布的代码不是有效的C ++(或我熟悉的任何其他语言).例如:

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

free(wchar_t);



是非法的.



is illegal.


此行:
free(wchar_t);


在我看来并不完全正确.

也不建议在静态指针上使用malloc和free.您应该在函数主体中分配一个新数组,并使调用方可随意调用它,或者要求调用方提供一个缓冲区以供新的wchar_t字符串使用.

另外我注意到您正在混合删除和免费.这是非常不安全的做法.您应该选择一种方法(malloc/free或new/delete)并坚持使用.


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.


我有Windows 2008 Server 64位.在这个运行32位应用程序的操作系统下(NB !!!!!不是我写的).这个应用程序(AspicMP-http://shop.kontron-czech.com/DetailPage.asp?DPG=69698)给了我机会,可以通过connectig dll扩展它的功能并使其发挥作用.我无法控制指针(删除)或使用指针地址进行任何维护.此应用程序有其自身的限制.
...
在Windows 32位环境下,此应用程序可以完美地与我的dll一起正常使用!!!
...
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!!!!
...


这篇关于在64位操作系统下获取wchar_t *的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆