|
Mahendra_786 wrote:
In your Dialog class add this to OnInitDialog:
m_myEdit.SubclassDlgItem(IDC_EDIT1, this);
This is highly unnecessary, and is handled automatically when a member variable is mapped to a control (using ClassWizard).
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
That is HIGHLY correct and
my way in fact may be insufficient not just unnecessary. In fact
DDX_* somewhere calls SubclassWindow to do this.
Moreover the way I suggested I am not sure how
UpdateData will work beside other side-effects.
Due Regards
Mahendra
|
|
|
|
|
Hello guys and girls
I was wondering if it's possible to programatically adjust the privileges of an application, running on let's say 2K/XP, so it can perform actions like installations and other restricted operations when the app is running at accounts without proper permissions. Is that possible at all?
Any information is appreciated.
Thanks in advance
|
|
|
|
|
Maybe it it were running as a service.
Kuphryn
|
|
|
|
|
Deian wrote:
I was wondering if it's possible to programatically adjust the privileges of an application...
Check out OpenProcessToken() and AdjustTokenPrivileges() .
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
I use the following code to enable "all" privileges, but still, after enabling them, I can't perform uninstall programatically What am I doing wrong?
DWORD dwLen;<br />
BOOL bRes = FALSE;<br />
HANDLE hToken; <br />
if (!OpenProcessToken(GetCurrentProcess(), <br />
TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) <br />
{ <br />
AfxMessageBox("no waaay!");<br />
} <br />
<br />
bRes = GetTokenInformation(<br />
hToken, <br />
TokenPrivileges, <br />
NULL, <br />
0,<br />
&dwLen<br />
); <br />
<br />
BYTE* pBuffer = new BYTE[dwLen];<br />
if(pBuffer == NULL)<br />
{<br />
CloseHandle(hToken);<br />
AfxMessageBox("no memory");<br />
} <br />
<br />
bRes = GetTokenInformation(<br />
hToken, <br />
TokenPrivileges, <br />
pBuffer, <br />
dwLen, <br />
&dwLen<br />
);<br />
<br />
if (!bRes)<br />
{<br />
CloseHandle(hToken);<br />
delete [] pBuffer;<br />
AfxMessageBox("Access denied");<br />
} <br />
<br />
TOKEN_PRIVILEGES* pPrivs = (TOKEN_PRIVILEGES*)pBuffer;<br />
for (DWORD i = 0; i < pPrivs->PrivilegeCount; i++)<br />
{<br />
pPrivs->Privileges[i].Attributes |= SE_PRIVILEGE_ENABLED;<br />
} <br />
bRes = AdjustTokenPrivileges(<br />
hToken, <br />
FALSE, <br />
pPrivs, <br />
0, NULL, NULL<br />
);<br />
<br />
delete [] pBuffer;<br />
CloseHandle(hToken); <br />
<br />
if (!bRes)<br />
AfxMessageBox("Access denied");<br />
else<br />
AfxMessageBox("success");
|
|
|
|
|
What is the return value of AdjustTokenPrivileges() ?
Deian wrote:
...but still, after enabling them, I can't perform uninstall programatically
What problems are you seeing?
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
Well, the return from the above code is "success". After that if I call GetLastError(), I get "Operation completed successfully". This means that all privileges are enabled, but still, when I try to programatically uninstall any aplication, I get an error, that the app is installed by user with administrative privileges and I can't uninstall such apps . I'm trying to perform this uninstall under restricted "Guest" account. I'm sure that there is a workaround for that though
|
|
|
|
|
Deian wrote:
when I try to programatically uninstall any aplication, I get an error
How are you doing this, and what is the error?
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
I'm executing the "UninstallString" value from the registry for any application, and it works perfectly - if it's let's say done under privileged account, the error is "A user with administrative privileges has installed this application, you can not uninstall it" or something similar. I get this error *ONLY* under restricted accounts under 2K/XP. It deals with system policy I guess, but I need a workaround so I can perform these "forbidden" actions.
Thanks for the attention and time spent Mr. Crow
|
|
|
|
|
I'm trying to read a file (which could be using ANSI or MBCS/UNICODE encoding) using the fgetws function, but am having problems. Here's my code:
FILE *file = fopen(tmp,"r");<br />
wchar_t *line = new wchar_t[2001];<br />
wcscpy(line,L"");<br />
wchar_t buf[501];<br />
while(fgetws(buf,500,file) != NULL)<br />
wcscat(line,buf);<br />
The problem is that only the first fgetws function call seems to work correctly; all the following calls return semi-invalid strings, almost double-UNICODE encoded: if there are, say, three spaces, they are stored as 00 00 00 32 00 00 00 32 00 00 00 32 in memory! I'm completely new to UNICODE programming, so I certainly could be making a simple mistake; I just haven't been able to find it yet
|
|
|
|
|
If opened in Text mode (the default), the MS C run-time treats the file as if it is ANSI (i.e. encoded using your default locale's character set). fgetws passes the data read through MultiByteToWideChar to get a UTF-16 string.
If the file is already UTF-16, you'll get the wrong answer (what you're seeing here).
Files opened in Binary mode (by adding a 'b' to the mode parameter) are treated as-is, with no conversions. This also means that CR+LF pairs are not converted to line feeds alone: you'll see \r as well as \n.
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
Ok, thanks for the help! So I'll just try reading the file as binary, and see how that works.
Is using fgetws the best way to fill a char array with the contents of a file, in a straight-Win32 app?
|
|
|
|
|
I have a dialog resource IDD_FORM_XXX in a project. I want to use this resource in another project. Can I copy the dialog resource into the other project?? I cant figure out how to do it...or how to import it.
Thanks.
Jerry
|
|
|
|
|
If nothing else you could copy the dialog from the resource (.rc) file and paste it into the new project.
- Aaron
|
|
|
|
|
I tried that. I dont know why but that will not work.
Jerry
|
|
|
|
|
Make sure you paste it in the dialog section of the new rc file. You will probably have to modify your resource.h for the IDs too.
"We have done so much in the last 2 years, and it doesn't happen by standing around with your finger in your ear, hoping everyone thinks that that's nice." - Donald Rumsfeld
|
|
|
|
|
open the two .rc (src and dest) file only in the same IDE.
then drag and drop from one window to another, if you hold the ctrl key down a copy will be made, else the resource will be moved.
Regards.
I'll write a suicide note on a hundred dollar bill - Dire Straits
|
|
|
|
|
Hi there,
Is there a way I can create a CComboBox pointer for a combo box that I have created within Resources? I want to be able to add items dynamically depending on user input. Whey can't it just do that in C++ like it does in ASP for select controls. The reason I ask is because I can't seem to position the dynamic combo box where I would like it. How to I find the coordinates for its position in order to position it properly?
For example, I have created a combo box in a dialog box which I will call IDD_COMBO. Its member variable defined in the header file is m_COMBO. Is it possible to add items to the box without having to create a CComboBox pointer?
Any help would be much appreciated. Thanks!
|
|
|
|
|
Right click on your combobox control, click class wizard...then click on member variables tab. Double click on IDD_COMBO in the list below and make sure your categorey is control NOT value.
Otherwise...
CComboBox* pControl = GetDlgItem(IDD_COMBO)
ASSERT(pControl);
pControl->AddString("My string ");
Cheers
How do I print my voice mail?
|
|
|
|
|
I had set the category to control and inserted the 3 lines of code above but it gave me the following error.
Error: cannot convert from 'class CWnd *' to 'class CComboBox *'
Also, how can I apply ON_CBN_SELCHANGE to a dynamic combo box?
Thanks!
|
|
|
|
|
If you set the categorey to control, you don't need the control pointer
instead you would
m_ctrlCombo.AddString("");
However, if your categorey was set to value because your relying on MFC's DDX and Updatedata() then keep it that way...so your combo is updated automagically...by the framework...
You will need a pointer if you want to add items dynamically...using AddString()...becuase value will store a member variable of type CString(I think) not CComboBox you can't call the string with a function like AddString...
Cheers
How do I print my voice mail?
|
|
|
|
|
Thanks Hockey! It worked!!!
|
|
|
|
|
In the class I'm writing I'm using the string type from the STL. The problem I'm encoutering is that when I compile I'm getting warning 4530 in a bunch of the STL string files. The warning is "C++ exception handler used, but unwind semantics are not enabled. Specify -GX" I see that I can just add the -GX compiler option, but I want to know why I'm getting this warning. I've used string before and never had this problem. In my header I have
#include <string>
using namespace std; Am I doing something wrong here?
- Aaron
|
|
|
|
|
MSDN states you need to enable exception handling for any of the standard C++ library.
http://support.microsoft.com/default.aspx?scid=kb;en-us;q154419[^]
Why you didn't get this warning before??? Maybe you weren't using MS STL Or perhaps your proejct settings already included this compiler switch?
Check out #pragma warning to surpress this warning
How do I print my voice mail?
|
|
|
|