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 4680
"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: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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: 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...
| |