|
I need to get the domain name for the currently logged on user.
::GetUserName gets me the user name, but how do I get the domain name for that user?
Thanks!
|
|
|
|
|
With, Win32_LogonSession you will get 'LogonId' use this logonId to query the Win32_LoggedOnUser. After querying 'Win32_LoggedOnUser' you will get all the fields, like - Domain, Name etc
Supriya
|
|
|
|
|
Use NetWkstaUserGetInfo [^] and retrieve level 1 information, as below. Requires Windows NT 3.1, 2000, XP, Vista.
#include <Windows.h>
#include <lm.h>
std::wstring GetDomainName()
{
WKSTA_USER_INFO_1* workstationInfo;
const NET_API_STATUS status = NetWkstaUserGetInfo(NULL, 1, (LPBYTE*)&workstationInfo);
if (status == NERR_Success)
{
return workstationInfo->wkui1_logon_domain;
NetApiBufferFree((LPBYTE*)&workstationInfo);
}
return std::wstring();
}
|
|
|
|
|
Another option is the environment variables USERDNSDOMAIN and USERDOMAIN.
Hope that helps.
Karl - WK5M
PP-ASEL-IA (N43CS)
PGP Key: 0xDB02E193
PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193
|
|
|
|
|
I am facing a run time problem with the CString in Release builds in vc6.0
i observed that the memory wont be released for cstring object i checked in the task manager can any one help for this here i posted the code also
#include "stdafx.h"
#include "afx.h"
#include "afxwin.h"
#include <windows.h>
#include "fixalloc.h"
#pragma warning (disable:4786)
#pragma warning (disable:4503)
#include<list>
#include<string>
#include<vector>
using namespace std;
#include <afxtempl.h>
void test()
{
vector<CString> stldmlist;
CString a;
FILE *fp=fopen("E:\\log1.txt","r");
char str[1000];
while(!feof(fp))
{
fscanf(fp,"%s\n",str);
a=str;
stldmlist.push_back(a);
}
fclose(fp);
AfxMessageBox("Memory");
}
UINT32 main(int argc, char* argv[])
{
CString obj;
AfxMessageBox("Start ");
test();
AfxMessageBox("End");
return 1;
}
Hi this Ravinder
|
|
|
|
|
Ramasani wrote: memory wont be released for cstring object i checked in the task manager
Given that task manager doesn't tell you if objects released memory or not, I presume you were looking at an process's working set...
The behaviour I'm guessing you're talking about (the process's working set rising and not falling after test exits) is to be expected - when you start allocating memory, the C runtime requests large chunks of memory from the Windows memory manager. It will not necessarily bother releasing them when you release objects, as allocating and releasing memory with the Windows memory manager is quite expensive.
|
|
|
|
|
if i go for more number of CString calls it returns memory leak errors(no memory) is there any patches available for this? i need very urgent.
Hi this Ravinder
|
|
|
|
|
Ramasani wrote: memory leak errors(no memory)
Ummm - 'no memory' does not necessarily imply memory leaks. It could just be that you're allocating a *lot* of memory. How big is this log file you're reading in?
Ramasani wrote: is there any patches available for this?
Let's think about this - what's more likely to be at fault - MFC/C++ standard libraries or your code/understanding thereof? Mmmm.
|
|
|
|
|
Actually i am using CString in my application more than 10k times and my apllication will run for days in this cases memory is not releasing thats the problem i have given a sample code only but it is working fine in Debug mode not in release mode ?
Hi this Ravinder
|
|
|
|
|
Ramasani wrote: it is working fine in Debug mode not in release mode
In what sense? You have not stated a) what you expected to observe when running in release mode and b) what actually did happen.
I've run your sample code (admittedly built with VS2003 rather than VC6) and monitored the execution of both debug and release variants with task manager and Process Explorer[^]. In both cases, it behaved exactly as I would expect.
|
|
|
|
|
yeh., Exactly its working in vs2003 and later but not vc6.0 my applications all are in vc6.0. i need patches without changing my application
Hi this Ravinder
|
|
|
|
|
Ramasani wrote: ...my apllication will run for days in this cases memory is not releasing...
Are you expecting this to happen automatically? Nowhere in your code are you directly calling new or delete .
It seems the problem and the code snippet you've shown are not related.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
|
|
|
|
|
Hi,
In our project I want to display Images in ListBox.I need to take Image from directory and print it in ListBox.
I am able to print Images in ListBox which are added as resources in the
project.But my requirement is I need to take Images from directory and print it in Listbox.How can I do that.
Regards,
Rekha.
|
|
|
|
|
Have a look at CImage to load the images from disk; after that, the code
to have them in the list should be quite similar to what you have now.
This signature was proudly tested on animals.
|
|
|
|
|
There are two methods,
Use CListCtrl instead of CListBox and do the following
Using LoadImage API (or CImage), you can load images from file. Add the Images to CImageList class using CImageList:Add interface and Set the image list using CListCtrl::SetImageList function.
Otherwise, create an owner-drawn CListBox and keep the list of Images in your class (You can use the previous methods mentioned to load images) and in DrawItem function, draw it inside each cell's rect.
-Sarath.
"Great hopes make everything great possible" - Benjamin Franklin
|
|
|
|
|
Hi,
Thanks for your replay .I am using LoadImage API. In our project we having images in one directory.Where should I place Image files. Will it load image from anywhere in the disk?
Rekha.
|
|
|
|
|
You can load from anywhere from a valid path. It's better to keep images in a separate folder under the executable's current directory.
Here's the sample code to load bmp using LoadImage API[^]
-Sarath.
"Great hopes make everything great possible" - Benjamin Franklin
|
|
|
|
|
thanks for your replay.I am able to print images in ListBox
Rekha.
|
|
|
|
|
See Image List Box[^].
Of one Essence is the human race
thus has Creation put the base
One Limb impacted is sufficient
For all Others to feel the Mace
(Saadi )
|
|
|
|
|
I have a created a SDI Application and 4 toolbar buttons are there, in that one button is PAUSE/RESUME button(Like a Toggle button). So when clikced PAUSE button means I have to change to RESUME image and Vice-versa. I have done it by using CImagList::Replace(index, IC_PASUSE).
Now i have created the modeless dialog and it contains one CButton. Her my aim to change the image of the Toolbar PAUSE/RESUEME button when i cliked that CButton in the Modeless dialog. For that I wrote same code that is CImageList::Replace(), But when i cliked that CButton in the modeless dialog , the image is not changing in the Toolbar PAUSE/RESUME button, but when i moves the mouse on the ToolBar PASU/RESUME button, that image is replacing perfectly.
provide me the solution.
|
|
|
|
|
You need to inform the main frame (or something) that the state of that command button has changed - maybe this page[^] can help?
You should probably not change the image list directly, instead send a message to the main frame telling it about the state change. Then it can manage the change to its UI.
|
|
|
|
|
CRect rText( 0, 0, 0, 0 );
pDC->;DrawText( str, rText, DT_CENTER |DT_CALCRECT |DT_WORDBREAK);
szText = rText.Size();
in rText i dnt get values at all they ramain same as 0 0 0 0 ny body help
thankz
|
|
|
|
|
(I hope str is not empty... )
_T("No name") wrote: pDC->;DrawText( str, rText, DT_CENTER |DT_CALCRECT |DT_WORDBREAK);
Shouldn't be
pDC->DrawText( str, &rText, DT_CENTER |DT_CALCRECT |DT_WORDBREAK);
?
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]
|
|
|
|
|
no that i have checked already string is nt empty
|
|
|
|
|
Have you added the address of operator to your function call?
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]
|
|
|
|