Dear All,
Many old C standard library is useful for string operation such as strcpy.
But I meet some problem, a managed char array which declared in a structure
and this structure has a instance declared in a__gc class.
Sample code as following,
namespace Configure
{
using namespace System ;
typedef struct _SW{
char szVersion[64] ;
} SW,*PSW ;
public __gc class Config{
private :
SW m_sw ;
public :
Config() { strcpy(m_sw.szVersion,"1.0.0.0") ; }
} ;
}
There is a complier error at strcpy() function: Can't conver char[64] to
char *.
My question is how to conver this managed char array to char* , thus, I can
use the standard C lib such as strcpy(), and strcat().
Does any can tell me the solution? Thank you very much.
Regards,
Tsung-yu 5 4688
"joye" <jo**@askey.com.tw> wrote in message news:<#9**************@TK2MSFTNGP09.phx.gbl>... Dear All,
Many old C standard library is useful for string operation such as strcpy. But I meet some problem, a managed char array which declared in a structure and this structure has a instance declared in a__gc class. Sample code as following,
namespace Configure { using namespace System ;
typedef struct _SW{ char szVersion[64] ; } SW,*PSW ;
public __gc class Config{ private : SW m_sw ; public : Config() { strcpy(m_sw.szVersion,"1.0.0.0") ; } } ; }
There is a complier error at strcpy() function: Can't conver char[64] to char *.
My question is how to conver this managed char array to char* , thus, I can use the standard C lib such as strcpy(), and strcat(). Does any can tell me the solution? Thank you very much.
Regards, Tsung-yu
Hi
This will do the magic:
Config()
{
Config __pin *This = this;
strcpy(This->m_sw.szVersion,"1.0.0.0") ;
}
To copy the native array you have to pin the gc class that hold it
before referring to a native function such as strcpy()
Alon Fliess
[VC++ MVP]
Hi Alon,
It's work. Thank you very much.
By the way, why I can't use this way as following,
strcpy((__pin char*)m_sw.szVersion,"1.0.0.0");
Regards,
Joye
--
Sent via .NET Newsgroups http://www.dotnetnewsgroups.com
Hello Alon,
I change the code a bit 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") ;
Config *pCfg2 = new Config(pCfg1->m_sw.szVersion) ;
-->Here still get an error : can't conver char[64] to char *
How to resolved this?
Thank.
Regards,
Joye
--
Sent via .NET Newsgroups http://www.dotnetnewsgroups.com
Hello Alon,
It's work, thank you very much.
Now, I change the code a bit 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") ;
Config *pCfg2 = new Config(pCfg1->m_sw.szVersion) ;
-->Here still get an error : can't conver char[64] to char *
How to resolved this?
Thanks.
Regards,
Joye
--
Sent via .NET Newsgroups http://www.dotnetnewsgroups.com
--
Sent via .NET Newsgroups http://www.dotnetnewsgroups.com
Hi
The problem in the code is the usage of the "this" keyword instead of
the "This" pinned pointer. If you find it confusing you may want to use
other name for the pinned pointer.
Just change the line to:
strcpy(This->m_sw.szVersion,sz*Version) ;
Alon Fliess
[VC++ MVP] This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Weston Fryatt |
last post by:
(Sorry for spamming multiple groups, But I need a solution to this problem)
I think this should be a simple question on Memory Allocation in a managed DLL and passing a memory pointer over to an...
|
by: Ekim |
last post by:
hello,
I'm allocating a byte-Array in C# with byte byteArray = new byte;
Now I want to pass this byte-Array to a managed C++-function by reference,
so that I'm able to change the content of the...
|
by: Omid Hodjati |
last post by:
Hi All,
I implemented an encryption algorithm using C#, native C++
and managed C++. Then I measured the CPU time used for
executing this algorithm in all implementation. The
managed version of...
|
by: joye |
last post by:
Hello,
How to convert an unmanaged string with char array type to a managed string
with char array type?
Thanks.
Regards,
Tsung-Yu
|
by: joye |
last post by:
Hello ,
I meet some data convertion problem, the sample code as following,
namespace Configure
{
using namespace System ;
typedef struct _SW{
char szVersion ;
| |
by: joye |
last post by:
Hello ,
I meet some data convertion problem, the sample code as following,
namespace Configure
{
using namespace System ;
typedef struct _SW{
char szVersion ;
|
by: Serge BRIC |
last post by:
My application, written in .NET VB, tries to get a communication port handle
from a TAPI object with this code:
Dim vFileHandle As Byte() = appel.GetIDAsVariant("comm/datamodem")
The...
|
by: Aston Martin |
last post by:
Hi All,
********************** My Situation **********************
I am working on project that involves passing a structure to unmanaged
code from .Net world (well using C#). Perhaps an example...
|
by: DavidT |
last post by:
Hello,
at first, exuse if the following question is simple to solve, but i normaly coding with C# and now have to use C++/CLI for one project.
My Problem is that i have to use a native c++ sdk...
|
by: DavidT |
last post by:
Hello,
at first, exuse if the following question is simple to solve, but i
normaly coding with C# and now have to use C++/CLI for one project.
My Problem is that i have to use a native c++ sdk...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
| |