c++ 中 string 转char

来源:百度知道 编辑:UC知道 时间:2024/05/22 19:10:47
#include "stdafx.h"
#include "dr.h"
#include <string>
using namespace std;

BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
{
string str;
str="加载成功!";
char p[]=str.c_str();
//id=GetCurrentProcessId();

MessageBox(NULL,p,"提示信息",MB_OK);
break;
}
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
{
MessageBox(NULL,"卸载!","提示信息",MB_OK);
break;
}
}
return TRUE;
}

组建的时候报错:

--------------------Configuration: dr - Win32 Debug--------------------
Compiling...
dr.cpp
d:\My Documents\VC\dr\dr.

1.
MessageBox(NULL, str.c_str(),"提示信息",MB_OK);

2.
const string str = "加载成功";
char szBuf[100];
strcpy( szBuf, str.c_str() );
MessageBox(NULL, szBuf提示信息",MB_OK);

关于c++ String建议你查看我写的《c++ String深入详解2.0版》PDF:
http://hi.baidu.com/_%E2d_%B7%B3_%DE%B2%C2%D2/blog/item/9d24e20196e43604728da547.html