|
Hi all,
I want to use of vector or list continer for adding structure to array, how can i do that ?
For example:
struct myLib
{
.
.
.
} NNN;
vector<<>myLib> vec1;
vec1.push_back(...);
Is it true ?
My month article: Game programming by DirectX by Lan Mader.
Please visit in: www.geocities.com/hadi_rezaie/index.html
Hadi Rezaie
|
|
|
|
|
struct myLib
{
.
.
.
} NNN;
vector<<>myLib> vec1;
vec1.push_back(...);
This will work, but if you use pointers to structs then you need to do this to dereference an iterator
(*it)->mymember
If you don't use pointers then you'll need to provide operator = for your struct if it contains any non-simple types. Of course, if it contains large items like a bitmap, this will also slow things down a *lot*. Finally, if you put pointers in, you need to call delete on them as you pop them from your vector, or remove them from your list.
Christian
Secrets of a happy marriage #27:
Never go to bed if you are mad at each other. It's more fun to stay up and fight.
|
|
|
|
|
Hi and thanks for your reply ...
Now, i know for adding new impelement to array i can use of vector or list continer ...
And i know vector can add new impelement in the last array and can't add new implement in middle the array, but list can ...
I wanna know, how ?
My month article: Game programming by DirectX by Lan Mader.
Please visit in: www.geocities.com/hadi_rezaie/index.html
Hadi Rezaie
|
|
|
|
|
Because a vector is an array, to put something in the middle you need to reallocate the whole memory block. The insert function allows you to do it, and if it's full of pointers then I guess it's not so bad. But the thing is if you want random insertion/deletion, you should go for a list. If however, the loss of speed for random access is a problem go map - it's a binary tree which gives a good compromise between fast random insertion and fast random access.
Christian
Secrets of a happy marriage #27:
Never go to bed if you are mad at each other. It's more fun to stay up and fight.
|
|
|
|
|
That's all there is to it. Just keep in mind that it's going to make a copy of the structure each time you call push_back. So depending on what you are storing in your structure it might be better to store a pointer to a structure.
|
|
|
|
|
Well...
I want to create my own application using the Apache server.
Actully, The main purpose is:
A: that the 'Apache' will recieve the data submited by the user from an html.
B: MyServer will get it from the 'Apache' ...
C: And send an answer to the user in XML format
(the XML That will be sent to the user doesn't matter)
Basicly, I want to send an answer to the user.
looking for the MINIMAL code needed,
or links to tutorials or somthin' like that.
10x.
STR
|
|
|
|
|
use cgi. read apache docs.
|
|
|
|
|
Howdy,
I used to know how to do this, but I've completely forgotten what I used to know. Here's the problem.
I have an MFC MDI application. I open it up with a new document. I use the document a while and then press select "File->Save" (or just press the disk icon).
The file dialog appears, open to the current working directory.
I don't want it to open to the CWD, I want the file save dialog to open to a directory that I specify.
How?
thanks
Jim
|
|
|
|
|
You can do it like this:
CFileDialog dlg(...); // whatever initialization you want
dlg.m_ofn.lpstrInitialDir = _T("C:\\My Folder");
dlg.DoModal();
Bret Faller
Odyssey Computing, Inc.
|
|
|
|
|
Thanks, but that doesn't apply here.
If you make a empty MDI app you'll see that it is the MFC framework that calls the FileDialog, not the application programmer.
So I need someway to tell the application framework what value I want to put into m_ofn.lpstrInitialDir before it calls the open/save file dialog.
Jim
|
|
|
|
|
How can you find this out?
Cathy
|
|
|
|
|
Use 'NetGroupGetUsers' from Netapi32.lib
Regards
Boris
NB On NT4 you have to use the english group name regardless of local settings - don't know if this is true for win2k. In any case, you should probably check different local settings...
|
|
|
|
|
Thanks for your answer but I don't know the word for administrator in all the different languages where the application will be deployed.
There has to be an easier way.
Cathy
|
|
|
|
|
Try this
If it works, maybe its a good one for the FAQ
|
|
|
|
|
It works! Thanks!
It's not short though. You have to define SetPrivilege(...)
BOOL SetPrivilege(
HANDLE hToken, // access token handle
LPCTSTR lpszPrivilege, // name of privilege to enable/disable
BOOL bEnablePrivilege // to enable or disable privilege
)
{
TOKEN_PRIVILEGES tp;
LUID luid;
if ( !LookupPrivilegeValue(
NULL, // lookup privilege on local system
lpszPrivilege, // privilege to lookup
&luid ) )
{ // receives LUID of privilege
printf("LookupPrivilegeValue error: %u\n", GetLastError() );
return FALSE;
}
tp.PrivilegeCount = 1;
tp.Privileges[0].Luid = luid;
if (bEnablePrivilege)
tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
else
tp.Privileges[0].Attributes = 0;
// Enable the privilege or disable all privileges.
AdjustTokenPrivileges(
hToken,
FALSE,
&tp,
sizeof(TOKEN_PRIVILEGES),
(PTOKEN_PRIVILEGES) NULL,
(PDWORD) NULL);
// Call GetLastError to determine whether the function succeeded.
if (GetLastError() != ERROR_SUCCESS)
{
printf("AdjustTokenPrivileges failed: %u\n", GetLastError() );
return FALSE;
}
return TRUE;
}
It's a common enough thing to have to do. I'm sure there must be some built in function somewhere.
|
|
|
|
|
Hi
OK - I didn't realize that SetPriviledge wasn't an API call - looks like you should work for Bill
I've messed it up a bit more, and humbly submit this orangey splotch of test level code, hastly hacked into an unsuspecting CMainFrame class:
BOOL CMainFrame::SetPriviledge(HANDLE hToken, LPCTSTR lpszPrivilege, BOOL bEnablePrivilege)
{
TOKEN_PRIVILEGES tp;
LUID luid;
if ( !LookupPrivilegeValue(
NULL,
lpszPrivilege,
&luid ) )
{
printf("LookupPrivilegeValue error: %u\n", GetLastError() );
return FALSE;
}
tp.PrivilegeCount = 1;
tp.Privileges[0].Luid = luid;
if (bEnablePrivilege)
tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
else
tp.Privileges[0].Attributes = 0;
AdjustTokenPrivileges(
hToken,
FALSE,
&tp,
sizeof(TOKEN_PRIVILEGES),
(PTOKEN_PRIVILEGES) NULL,
(PDWORD) NULL);
int err = GetLastError();
if(0 != err)
{
LPVOID lpMsgBuf;
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
err,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR) &lpMsgBuf,
0,
NULL
);
char buf[256];
sprintf(buf,"SetPriviledge failed:\n\n%s",lpMsgBuf);
MessageBox( buf, "Error", MB_OK | MB_ICONINFORMATION );
LocalFree( lpMsgBuf );
return FALSE;
}
return TRUE;
}
void CMainFrame::OnAdminLookup()
{
HANDLE hToken;
if (!OpenProcessToken( GetCurrentProcess(),
TOKEN_ADJUST_PRIVILEGES, &hToken) )
{
char buf[80];
sprintf(buf,"OpenProcessToken failed: %u\n", GetLastError() );
MessageBox(buf);
}
else {
if(!SetPriviledge(hToken,SE_TAKE_OWNERSHIP_NAME,TRUE)) {
}
}
}
With the FormatMessage thingy you should get a 1300 ERROR_NOT_ALL_ASSIGNED with the "Not all priviledges referenced are assigned to the caller." message displayed, for whatever that's worth.
Works on Win 2000 as well. Nice work.
|
|
|
|
|
Oh...I didn't do any work. I copied that function out of the MSDN topic "Take Object Ownership". I believe you referenced it in your post. You should submit your new and improved version to Microsoft. Then maybe you could go to work for Bill. Yes, I know you probably don't want to.
I'm going to try NetUserGetInfo(..) when I get back to that project. If it doesn't work out I'll use your new and improved version of SetPrivilege(...)I'll let you know so you can add it to the FAQ's page.
Thanks again for your help!
P.S.
How do you do the orange block of code in the forums?
|
|
|
|
|
Surround it with <pre> </pre> tags:
Jon Sagara
Sagara Software
|
|
|
|
|
Thanks! (sorry had to try it out)
Cathy
|
|
|
|
|
Hi
Just use the html <pre> and </pre> tags in your text - if you want < and > to actually show up, use < and >.
Yes, it looks like NetUserGetInfo is the way to go. I just did a test where I fired all the privileges at SetPriviledge and found about 5 that failed, so in a sense there might be a finer grain available here, but wadduino.
Guess originally it was a question of finding an alternative to NetUserGetInfo, so in that sense nothing lost!
Cheers
T
-----
Would anyone have a spare signature I could use?
|
|
|
|
|
Call NetUserGetInfo() with level 3.
Jon Sagara
Sagara Software
|
|
|
|
|
Thanks!
|
|
|
|
|
Hello all,
I need to determine if a given port number is available for a socket. Please correct me if I'm wrong, but I think the reserved port numbers are output by "netstat /a". I'm guessing there's something in Winsock that lets me test for a given port's availability, but I'm not sure. Can anyone suggest how I can do this? Thanks.
|
|
|
|
|
Its all a little fuzzy, but I think a call to bind should fail if the sockets local address + local port specified in the SOCKADDR is already in use.
Also, winsock has the ability to bind to a port generated for you (specify a 0 for port), which you can query with getsockname .
|
|
|
|
|
What is the MFC function call to allow a resouce dll to run within the context of an application without resource ID conflicts?
|
|
|
|