how to convert managed char array to unmanaged char*?

J

joye

Hello ,

I meet some data convertion problem, the sample code as following,

namespace Configure
{
using namespace System ;

typedef struct _SW{
char szVersion[64] ;
} SW,*PSW ;

public __gc class Config{
public :
SW m_sw ;
public :
Config(char *szVersion)
{
Config __pin *This = this ;
strcpy(this->m_sw.szVersion,szVersion) ;
} ;
}

Assume the calling code as following,

Config *pCfg1 = new Config("1.0.0.1") ;
char szVer[64]="Application ver." ;
szVer=strcat(szVer,pCfg1->m_sw.szVersion) ;

-->Here still get an error : can't conver char[64] to const char *

My question is how to convert managed char array to unmanaged char*?
Does anyone can help me to resolved this problem? Thank you very much.

Tsung-Yu
 
M

Markus Minichmayr

Although you get a pinned pointer to "this" in the constructor, you use the
unpinned version in your call to strcpy. Try to use the pinned version
"This" instead!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top