Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 496
  • Last Modified:

converting DDX_TEXT data to char[]

Hello all,

I have a Dialog that accepts data into a variable m_myvar.  I need to feed this to a function that is expecting a char[]  Is there any way to convert the data from a DDX_TEXT box to char[].  I don't want to change the whole function.

DDX_TEXT(pDX, IDC_EDIT1, m_myvar);

I need m_myvar to be turned to  a char[].

Thanks!
0
bluedragon99
Asked:
bluedragon99
  • 9
  • 5
1 Solution
 
bluedragon99Author Commented:
CString to char * would work for me too....HELP!!
0
 
bkfirebirdCommented:
Hi,

What is the datatype of m_myvar ? If it is a CString, then you can simply type cast it.

-Kiran Adigopula
0
 
bluedragon99Author Commented:
I can use anything DDX_TEXT accepts for an edit box.  CString would work I belive.  I am really new to c++, how would I convert a cstring to char?
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
bkfirebirdCommented:
try (LPSTR) m_myvar
or (LPSTR)(LPCTSTR) m_myvar

0
 
bluedragon99Author Commented:
will a function expecting a char accept an lpstr, again I am pretty much a newbie to c++.  Where would I use this right before the function call to convert the type to what it is expecting?
0
 
bluedragon99Author Commented:
How and where would I go about defining the DDX_TEXT var?
0
 
bkfirebirdCommented:
you can declare the variable in your class variables ...

class myclass
{
public :
CString m_myvar;
....................
};

if you have a function which takes a character array as input ....
void printstr (char * str)
{
   printf("\ntest %s", str);
}

you can call it as .....
printstr ((LPSTR)(LPCSTR)m_myvar);

hope this helps
0
 
bluedragon99Author Commented:
ok m_Data is declared as a global CString now.

function call looks like this now

send(.........other stuff here.....................................m_data,strlen(m_data))

function looks like:

BOOL CUDPSocket::Send(int iSourcePort,LPCSTR lpDestinationAddress,int iDestinationPort, char* buf,int BufLength)


I am completly lost here, sorry for being such a pain but I have been working on a solution for this for DAYS with no luck...:(
0
 
bluedragon99Author Commented:
arrrrrrrrrrgggggggggggggg m_data keeps coming up UNDECLARED when it declared in the friggen header file as extern?!?!???!??
0
 
bkfirebirdCommented:
call the function like this ...

send(.........other stuff here...................................., (LPSTR)(LPCSTR)m_data,m_data.GetLength())
0
 
bluedragon99Author Commented:
oops sorry had m_data instead of m_Data, still don't know how to correct this though..

ok m_Data is declared as a global CString now.

function call looks like this now

send(.........other stuff here.....................................m_data,strlen(m_data))

function looks like:

BOOL CUDPSocket::Send(int iSourcePort,LPCSTR lpDestinationAddress,int iDestinationPort, char* buf,int BufLength)
0
 
bluedragon99Author Commented:
will m_data.GetLength() work without any changes to the current function:


int BufLength
0
 
bkfirebirdCommented:
yes, it should work fine
0
 
bluedragon99Author Commented:
You know your stuff man it worked like a charm!  THANKS!!!!
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 9
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now