Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

converting DDX_TEXT data to char[]

Posted on 2004-04-09
14
Medium Priority
?
480 Views
Last Modified: 2013-11-20
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
Comment
Question by:bluedragon99
  • 9
  • 5
14 Comments
 
LVL 1

Author Comment

by:bluedragon99
ID: 10794548
CString to char * would work for me too....HELP!!
0
 
LVL 4

Expert Comment

by:bkfirebird
ID: 10794554
Hi,

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

-Kiran Adigopula
0
 
LVL 1

Author Comment

by:bluedragon99
ID: 10794584
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 4

Accepted Solution

by:
bkfirebird earned 2000 total points
ID: 10794593
try (LPSTR) m_myvar
or (LPSTR)(LPCTSTR) m_myvar

0
 
LVL 1

Author Comment

by:bluedragon99
ID: 10794622
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
 
LVL 1

Author Comment

by:bluedragon99
ID: 10794634
How and where would I go about defining the DDX_TEXT var?
0
 
LVL 4

Expert Comment

by:bkfirebird
ID: 10794657
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
 
LVL 1

Author Comment

by:bluedragon99
ID: 10794726
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
 
LVL 1

Author Comment

by:bluedragon99
ID: 10794739
arrrrrrrrrrgggggggggggggg m_data keeps coming up UNDECLARED when it declared in the friggen header file as extern?!?!???!??
0
 
LVL 4

Expert Comment

by:bkfirebird
ID: 10794743
call the function like this ...

send(.........other stuff here...................................., (LPSTR)(LPCSTR)m_data,m_data.GetLength())
0
 
LVL 1

Author Comment

by:bluedragon99
ID: 10794749
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
 
LVL 1

Author Comment

by:bluedragon99
ID: 10794782
will m_data.GetLength() work without any changes to the current function:


int BufLength
0
 
LVL 4

Expert Comment

by:bkfirebird
ID: 10794797
yes, it should work fine
0
 
LVL 1

Author Comment

by:bluedragon99
ID: 10794882
You know your stuff man it worked like a charm!  THANKS!!!!
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

886 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question