Solved

converting DDX_TEXT data to char[]

Posted on 2004-04-09
14
447 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

 
LVL 4

Accepted Solution

by:
bkfirebird earned 500 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

635 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