Solved

converting DDX_TEXT data to char[]

Posted on 2004-04-09
14
435 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
Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 
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 is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Suggested Solutions

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
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.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

770 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