|
error1408 wrote: Helper::instance()->strtoken(name, ".", token);
How about something like:
char *temp = new char[strlen(name) + 1];
strcpy(temp, name);
Helper::instance()->strtoken(temp, ".", token);
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
DavidCrow wrote: How about something like:
char *temp = new char[strlen(name) + 1];
strcpy(temp, name);
Helper::instance()->strtoken(temp, ".", token);
Ok this works! But I don't understand why...could someone explain it to me? Why does the param char * not work but the char * thats created here?
Btw. I have to DELETE the char *temp afterwards, right?
|
|
|
|
|
error1408 wrote: Why does the param char * not work but the char * thats created here?
Work through this:
void main( void )
{
char *abc = "First";
char xyz[] = "Last";
abc[0] = '1';
xyz[0] = '2';
}
error1408 wrote: Btw. I have to DELETE the char *temp afterwards, right?
Correct (since it points to heap memory).
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
Ok I think I got it. So is it right, that in my case I can not know if the char *name that I get is a literal or not so to be sure it's not I have to create a temp array?
|
|
|
|
|
error1408 wrote: ...I can not know if the char *name that I get is a literal or not so to be sure it's not I have to create a temp array?
You'll notice in my example that both variables pointed to a string literal, yet only one of them could be changed. Therein lies the difference between a char* vs. char[] . See here for more.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
i agree with the pallini's solution and also david gave a good description. string literals r located in a const part of memory which is not writable. this is why arrays don't cause crash. they're located in heap or stack based on whether u allocate them or use local variables which r both writable parts of memory.
there's an API function to determine whether a block of memory or a string is const named AfxIsValidAddress. it may also test whether the block is writable. but if i were u, i would use _strdup anyway, and would pass the arg as const for the caller to make sure that the original version of the passed string is not altered.
|
|
|
|
|
Hi,
I have a header control(i.e CHeaderCtrl). In which I created 5 column. But my requirement is that only 1st column should not move(by dragdrop operation). How to make the perticular column non-movable?
For this I am thinking of reordering the 1st column to orignal position i.e 1st. But how to change the column order programatically?
Thanks:-
Mike
|
|
|
|
|
Check out the HDS_DRAGDROP style and the HDN_xxx notifications.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
I'm working on a list control application. When i double click on a row, i want to save the data in the 3rd column of that selected row to be store in a string.
Please tel me know how can this be achieved.
Thanks in Advance
|
|
|
|
|
You can do that using the CListCtrl class
The following member functions need to be used -
GetFirstSelectedItemPosition<br />
GetNextSelectedItem<br />
GetItemText
«_Superman_»
|
|
|
|
|
// Map double click using event handling
ON_NOTIFY(NM_DBLCLK, IDC_LIST1, &CListSampleDlg::OnNMDblclkList)
// in the callback function
void CListSampleDlg::OnNMDblclkList(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMITEMACTIVATE pNMItemActivate = reinterpret_cast<lpnmitemactivate>(pNMHDR);
CString str = m_List.GetItemText( pNMItemActivate->iItem, 2 );
AfxMessageBox( str );
*pResult = 0;
}
</lpnmitemactivate>
is this what you want?
-Sarath.
"Great hopes make everything great possible" - Benjamin Franklin
|
|
|
|
|
Thank you for the code. Though it wasn't working I got an idea and completed the required one.
But if i want to save the data of the 3rd column in a string of about more than one selected rows with "|" as separator. Please let me know how can this achieved.
Thanks in advance
|
|
|
|
|
I believe Superman already given you idea on getting text of selected items.
Here's the code snippet. Please check MSDN.It contains lot of sample snippet with documentation
CString strColumText;
POSITION pos = m_List.GetFirstSelectedItemPosition();
if (pos == NULL)
{
TRACE(_T("No items were selected!\n"));
}
else
{
while (pos)
{
int nItem = m_List.GetNextSelectedItem(pos);
strColumText += _T("|") + m_List.GetItemText( nItem, 2 );
}
}
-Sarath.
"Great hopes make everything great possible" - Benjamin Franklin
|
|
|
|
|
I have propertysheet with three dialogs.
I want to process them automatically by calling OnWizardNext() in OnSetActive() method for not showing that dialog. It is working fine except for the final dialog. For the final dialog I am calling OnWizardFinish()on OnSetActive() of that dialog so that finish button functionality should automatically called but still I see that final dialog and need to press that finish button(don't know what am I missing).
Can anyone please help me in that.
Thanks,
Mushtaque Nizamani
|
|
|
|
|
Try calling DestroyWindow at the end.
«_Superman_»
|
|
|
|
|
Thanks for the reply.
still no luck, now it displays corrupted final dialog with finish button.
Regards,
Mushtaque Nizamani
|
|
|
|
|
Why to give a call to the dialog when you intend to kill it explicitly without user intervation?
BTW did you try PressButton(PSBTN_FINISH)
You need to google first, if you have "It's urgent please" mentioned in your question.
_AnShUmAn_
|
|
|
|
|
Hi. I'm trying to send an array of UDT from Excel VBA to a C++ dll but have no idea which direction I should look. Here's what I'm trying to do
MyTestDLL.cpp
#pragma pack(4)
struct MyCppType
{
short iVal;
double dVal;
BSTR bstr;
};
#pragma pack()
void _stdcall MyDllFunction (array of MyCppType)
{
}
MyTestDLL.def
LIBRARY "MyTestDll"
EXPORTS
MyDllFunction @1
MyTestExcel.xlsm
Option Explicit
Declare Sub MyDllFunction Lib "MyTestDLL.dll" (arr() As MyVbaType)
Type MyVbaType
iVal As Integer
dVal As Double
sVal As String
End Type
Sub Test()
Dim arr(2) As MyVbaType
arr(1).iVal = 1
arr(1).dVal = 1.1
arr(1).sVal = "one"
arr(2).iVal = 2
arr(2).dVal = 2.2
arr(2).sVal = "two"
MyDllFunction (arr)
End Sub
I've posted this problem on the VB forum and was advised to post it here. Please help
|
|
|
|
|
Hi I need to do the same thing. Can anyone give any pointers to it plz....
|
|
|
|
|
Hi,
I using MFC in my Application.My Application single document Application. I have selected Document/view architecture support and Unicode Libraries.
I want to Print Images in ListBox. I have created one Dialog which is having ListBox and added class to it. I have written one Abstract class. In that I have decleared Pure virutul functions.
class CDrawC
{
protected:
virtual void DrawItem(LPDRAWITEMSTRUCT lpdis, bool bHasFocus) = 0;
virtual void MeasureItem(LPMEASUREITEMSTRUCT lpmis) = 0;
virtual void InitLBox(CListBox* pLBox) = 0;
virtual int AddItemLst(CListBox* pLBox, char* Item) = 0;
friend class CODrawLBox;
};
I have derived class from above class and overriden the functions DrawItem(),MeasureItem() and AddItemLst().
class CPicDrawC : public CDrawC
{
public:
CPicDrawC() : PicSizeX(200), PicSizeY(200) {}
const int PicSizeX;
const int PicSizeY;
protected:
virtual void DrawItem(LPDRAWITEMSTRUCT lpdis, bool bHasFocus);
virtual void MeasureItem(LPMEASUREITEMSTRUCT lpmis);
virtual void InitLBox(CListBox* pLBox) {}
virtual int AddItemLst(CListBox* pLBox, char* nItem);
};
I have created ListBox variable and changed its type to CODrawLBox Class type which is derived from CListBox.
class CODrawLBox : public CListBox
{
DECLARE_DYNAMIC(CODrawLBox)
public:
CODrawLBox();
virtual ~CODrawLBox();
void SetDrawC(CDrawC* pDrwC) {
m_pDrawC = pDrwC;
}
void Init() {
m_pDrawC->InitLBox(this);
}
int AddItem(char* Item)
{
return m_pDrawC->AddItemLst(this, Item);
}
protected:
DECLARE_MESSAGE_MAP()
public:
virtual void MeasureItem(LPMEASUREITEMSTRUCT );
virtual void DrawItem(LPDRAWITEMSTRUCT );
protected:
CDrawC* m_pDrawC;
};
In the OninitDialog of Dialog I am using following code to display images.
char* path = new char[128];
strcpy(path,"C:\\ProgramFiles\\MTAF\\Reports\\Tc_1_11032008_083859123_2.bmp");
m_picList.AddItem(path);
Images are not displaying in ListBox.I am sure I am missing something.what will be the reason.
Regards,
Rekha.
|
|
|
|
|
hemlat wrote: .I am sure I am missing something.what will be the reason.
On the information given, you could be missing a lot of things.
1/ Why have you got a pure virtual class? That makes no sense to me.
2/ Is you list box owner draw? You need to pick Owner draw fixed or Owner draw variable.
3/ If you have the owner draw style set, the listbox will send WM_MEASUREITEM messages to your dialog box. You need to have a afx_msg void OnMeasureItem( int nIDCtl, LPMEASUREITEMSTRUCT lpMeasureItemStruct ); member function in your dialog box, and ON_WM_MEASUREITEM( ) in your message map to route messages to the function.
4/ Similarly, you'll need afx_msg void OnDrawItem( LPDRAWITEMSTRUCT ); / ON_WM_DRAWITEM( )
You could also look here on codeproject for listboxes that do owner draw things already. I know I've posted some combobox articles which are similar.
Good luck,
Iain.
Codeproject MVP for C++, I can't believe it's for my lounge posts...
|
|
|
|
|
Hi thanks for your replay.
My ListBox is owner draw variable.
I have overriden functions of CDialog.Those functions are
virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);
virtual void MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct);
I will try using Messages Maps
Rekha
|
|
|
|
|
If you do not have the entries in your message map, then MFC will not bother calling your functions. Simple as that.
Try using class wizard - it's quite good at adding these sort of entries.
Iain.
Codeproject MVP for C++, I can't believe it's for my lounge posts...
|
|
|
|
|
In the extension dll, I do not accept or reject request from client.I just get the attributes and write them to txt file,and then let IAS deal with the request.
In this way,if client request using PAP,I can get the ratUserPassword in txt file.
If client request using CHAP,I can get the ratCHAPPassword in txt file.
But if client request using MS-CHAP,I can get neither ratUserPassword nor ratCHAPPassword.
Please attention :
1) I do not accept or reject request in extension dll.
2) With my extension dll,VPN and IAS work perfect.Client can connect to VPN and pass the IAS's Authentication.
I can not understand why I can get neither ratUserPassword nor ratCHAPPassword if client request using MS-CHAP.
|
|
|
|
|
I've a third-party console application 'MyTestConsole.exe' that I launch by CreateProcess.
STARTUPINFO StartUpInfo;
PROCESS_INFORMATION ProcInfo;
memset(&StartUpInfo, 0, sizeof(StartUpInfo));
memset(&ProcInfo, 0, sizeof(ProcInfo));
StartUpInfo.dwFlags = STARTF_USESHOWWINDOW;
StartUpInfo.wShowWindow = SW_SHOWNORMAL;
CreateProcess( "D:\\MyTestConsole.exe", NULL, NULL, NULL, NULL, CREATE_NEW_CONSOLE, NULL, NULL, &StartUpInfo, &ProcInfo);
The console application launches successfully, but displays a standard windows error message, say for instance
'Error : could not open file'
Now, how do I get the error string 'Error : could not open file' in a CString object.
May be I'll have to use AttachConsole() and other console functions but not sure how.
Pleae give your suggestions.
Thanks in advance.
|
|
|
|