|
Hi
just a quick question from a novice programmer.
I want a storage class that only allows one instance of each thing like
set<cstring> myList;
but I want the items to be kept in sequential order
For example
I want to add "John" to the set.
Then I want to add "Peter".
Then "Chris".
Then I try and add "Peter" again it won't do it, so my set is still [John, Peter, Chris]
and then it keeps them in the order I entered them
so when I can ask for the second item I added I get "Peter.
My understanding of set<cstring> is when I insert a new member it will put it it alphabetical order.
any ideas??
|
|
|
|
|
yeah, easy.
Make a linked list, then upon adding a new item it gets added as a new node on the tail end of the list.
A little something like this, though with UNICODE & c++ support. There's linked lists in the stl now, but linked lists are a good educational tool, imho - hence my recommendation to write some code that uses your own implementation of them at least once.
struct myListItem
{
char *itemText;
int origPos;
myListItem *nextItem;
myListItem *prevItem;
};
myListItem *add(myListItem *linkedListHead, char *newText)
{
myListItem *curItem;
bool alreadyExists = false;
int curItemNum = 0;
curItem = linkedListHead;
if (curItem != NULL)
do
{
if (!strcmp(curItem->itemText, newText))
return curItem;
curItem = curItem->nextItem;
curItemNum++;
}while (curItem->nextItem != NULL);
else return NULL;
curItem->nextItem = (myListItem*) malloc(1*sizeof(myListItem));
curItem->nextItem->prevItem = curItem;
curItem->origPos = curItemNum;
curItem = curItem->nextItem;
curItem->itemText = (char*) malloc(strlen(newText)+1);
strcpy(curItem->itemText, newText);
return curItem;
}
|
|
|
|
|
All,
My environment is Windows XP 64 bit and am running 32 bit applications. When trying to attach memory validator to a running process, its not allowing me to do so. It shows a dialog box with "dll injection failed".
Any clue to resolve this would be of great help. Mem validator has helped us a great deal in the WinXP 32 bit world. But am not able to make it work in the 64 bit world.
Please let me know what am I missing?
Thanks
Rajdeep
|
|
|
|
|
I am working on a library that will process large (>4GB) files and I need to be able to randomly access the data.
STL's seekg() only appears to use int s which limits me to 2GB.
Any suggestions?
THanks.
|
|
|
|
|
Trollslayer wrote: Any suggestions?
Per Microsoft, any file greater than 2GB can not be read using the fstream class. This is a limitation in the stream I/O functions. For Win32, check out SetFilePointer() . Otherwise, you could use the lowest I/O in the CRT: open/_read/_write/_lseek/_lseeki64.
"Love people and use things, not love things and use people." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
|
|
|
|
|
Thanks, SetFilePointer() looks the best option.
|
|
|
|
|
My MFC SDI application lists the recently used files under File/Recent menu. Where does it get this information? Has my program registered itself in the registry? I don't have an installation feature with my app. Or is it getting this info from some operating system feature?
|
|
|
|
|
frqftgbdafr wrote: Where does it get this information?
By calling LoadStdProfileSettings() .
frqftgbdafr wrote: Has my program registered itself in the registry?
Yes.
"Love people and use things, not love things and use people." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
|
|
|
|
|
Thank you! I was wondering, is there an easy way to have my app store it's current window size and screen position into the registry on close? (MFC SDI). Thanks again
|
|
|
|
|
You can insert your data to registry see here[^].
|
|
|
|
|
frqftgbdafr wrote: I was wondering, is there an easy way to have my app store it's current window size and screen position into the registry on close?
Yes, use SetWindowPlacement() and GetWindowPlacement() in the frame's ActivateFrame() and DestroyWindow() methods.
"Love people and use things, not love things and use people." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
|
|
|
|
|
First of all i would like to say am very new to C++ and am probably asking somethingthing very simple. i am trying to write a win32 console application that moves files from one folder to another on the same drive.
when i call the win32api's MoveFile function it fails with the following error "The filename, directory name, or volume label syntax is incorrect". below is the offending piece of code.
i have checked the file exists and the destination folder also exists.
void BackupFile(string* origpath,string* filename,string* unitid,string* owner,string*month)
{
WIN32_FIND_DATA win32_find_data;
HANDLE handle;
string dest;
dest = "C:\\data_2008\\" + *owner + "\\" + *unitid + "\\"+ *month;
handle = FindFirstFile((dest+"\\*.*").c_str(),&win32_find_data);
if(handle != INVALID_HANDLE_VALUE)
{
dest += "\\" + *filename;
if(!(MoveFile(origpath->c_str(),dest.c_str())))
{
DeleteFile(origpath->c_str());
}
}
}
any help will be highly appreciated
|
|
|
|
|
Have you consulted a debugger?
|
|
|
|
|
|
i should have mentioned that when i check the values in the debugger the values are correct and are pointing to the correct paths.
i have managed to narrow down further and the problem seems to be the dest.c_str() while trying to move the file.
if i substitute it with the actual value it seems to work fine.
i have also tried replacing the datatype to LPCTSTR and below are the result
LPCTSTR sourcePath = "C:\\somefolder\\file.ext";
LPCTSTR destPath = "C:\\folder2\\file.ext";
LPCTSTR sourcePath = origpath->c_str();
LPCTSTR destPath = "C:\\folder2\\file.ext";
LPCTSTR sourcePath = origpath->c_str();
LPCTSTR destPath = dest.c_str();
i get the same when i change the datatype to a CString
any help will be highly appreciated
|
|
|
|
|
What are you doing with sourcePath and destPath ? Make sure that dest and origpath are still in scope, because otherwise the objects will be destroyed and sourcepath and destPath will point to memory which has been deleted. Make sure also that you don't modify the string objects in between. The two LPCTSTR point to an internal buffer of the string object, so if you modify the string object, this buffer can be destroyed.
|
|
|
|
|
i have checked and the values are not being modified, i have put a break point on the MoveFile line and the variables still hold the correct value.
i have created a MFC dialog based test application and pasted the exact same code and it works fine but fails in the win32 console application,
any ideas?
|
|
|
|
|
Good question.
Many are stubborn in pursuit of the path they have chosen, few in pursuit of the goal - Friedrich Nietzsche
.·´¯`·->Rajesh<-·´¯`·.
[Microsoft MVP - Visual C++]
|
|
|
|
|
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
hi
i need to add Ip Address as the value for the registry.
Example,like this
Registry Name = public
Registry Type = REG_SZ
Registry Data = 10.20.40.80
but using below code am able to add only one value as "1"
#include "stdafx.h"
#include <windows.h>
#include <stdio.h>
int _tmain(int argc, _TCHAR* argv[])
{
unsigned char szStr[20]="12.45.67.89";
HKEY hKey;
// opening a subkey, then creating and setting a value
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, TEXT
("SYSTEM\\CurrentControlSet\\Services\\SNMP\\Parameters\\s1"), 0,
KEY_ALL_ACCESS, &hKey)!=ERROR_SUCCESS)
printf("\nError opening the desired subkey (doesn't exist?).\n");
else
{
if (RegSetValueEx(hKey, TEXT("public"), NULL, REG_SZ, szStr, sizeof
(szStr)) ==ERROR_SUCCESS)
printf("\nThe value of the key was set successfully.\n");
else
printf("\nError setting the value of the key.\n");
}
RegCloseKey(hKey);
return 0;
}
Output am getting in the registry data field is " 9"
could you please help me regarding the above issue.
|
|
|
|
|
You are being very good about using TEXT macros, and TCHAR... while leads me to think you are using UNICODE.
In which case, your address needs to be stored as a TCHAR array also.
Ie:
TCHAR szStr [] = _T("12.45.67.89");
...
if (RegSetValueEx(hKey, TEXT("public"), NULL, REG_SZ, (BYTE *)szStr, sizof (TCHAR) * lstrlen (szStr)) ==ERROR_SUCCESS)
...
I'm assuming your access of hKey is succeeding?
Can you delete the "public" value using regedit, and see it getting re-created?
Iain.
|
|
|
|
|
thanks Iain Clarke
it's working fine.........
|
|
|
|
|
<code>TCHAR</code> szStr[20]= <code>_T(</code>"12.45.67.89"<code>)</code>;
HKEY hKey;
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,
_T("SYSTEM\\CurrentControlSet\\Services\\SNMP\\Parameters\\s1"),
0, KEY_ALL_ACCESS, &hKey) != ERROR_SUCCESS)
{
printf("\nError opening the desired subkey (doesn't exist?).\n");
}
else
{
if (RegSetValueEx(hKey, _T("public"), NULL, REG_SZ, <code>(const BYTE *)</code>szStr, <code>(_tcslen(szStr)+1)*sizeof(TCHAR)</code>) == ERROR_SUCCESS)
printf("\nThe value of the key was set successfully.\n");
else
printf("\nError setting the value of the key.\n");
<code>RegCloseKey(hKey);</code>
}
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
thanks Mark Salsbery
the above sample program is working fine, am able to enter the Ip Address properly.
thanks a lot
|
|
|
|
|
Hi,
I am using a CListCtrl in a dialog box. The column headings are initialized in OnInitDialog() function.
Now what i want a certain butoon on Dialog box the Column header should change dynamically.
Please Tell me how to do this.
Thanks in Advance.
Dhiraj Kumar Saini
|
|
|
|