|
You have to open the process token, then check to see which group the user is a member of.
I don't recall the functions involved, but if you google, you'll find it.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Run this piece of code -
HANDLE hProcess = ::GetCurrentProcess();
HANDLE hToken;
::OpenProcessToken(hProcess, TOKEN_QUERY, &hToken);
PTOKEN_ELEVATION_TYPE ele = 0;
DWORD dwLen;
::GetTokenInformation(hToken, TokenElevationType, (LPVOID)ele, 0, &dwLen);
ele = (PTOKEN_ELEVATION_TYPE)::HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dwLen);
::GetTokenInformation(hToken, TokenElevationType, (LPVOID)ele, dwLen, &dwLen);
ele will be TokenElevationTypeFull if run with admin privileges and TokenElevationTypeLimited if not.
The above code will check the current process.
To check for other processes, as others have said, you need to open the process to get its handle.
«_Superman_»
I love work. It gives me something to do between weekends.
Microsoft MVP (Visual C++) (October 2009 - September 2013) Polymorphism in C
|
|
|
|
|
thanks to all of you for valuable suggestion and help.
thanks alot.
but i have one another problem this works on vista and 7 but on XP, GetTokenInformation fail with invalid parameter.
please help me for this.
thanks.
modified 27-Nov-13 8:03am.
|
|
|
|
|
I am trying to get users name using traversing c:\users but I am getting 3 user name extra which does not in that folder i.e. All Users, Default User, Public.
How can I get exact users name?
|
|
|
|
|
john5632 wrote: How can I get exact users name? Which one? The one logged in to the PC? The one running your program? Be specific. Have you looked into GetUserName() ?
"One man's wage rise is another man's price increase." - Harold Wilson
"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
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
|
I have a regular DLL that uses MFC statically linked.
When I try to export a function with a c-style unmangled name, the DLL ends up being built with a mangled name for the function.
The function I'm exporting is defined as follows:
extern "C"
{
_declspec(dllexport) _LaunchProcess __stdcall Start(LPCLIENT32STARTUPCONTEXT StartupContext)
{
theApp.Start(StartupContext);
return &LaunchProcess;
}
}
When I build the DLL, the function ends up named "_Start@4" instead of just "Start". Does anyone know how I can force it to export the function as "Start"?
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
|
I'll try it, thanks.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
It worked, thank you.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
The MSDN documentation describes this - dllexport, dllimport[^]
Here is the excerpt from the documentation -
dllexport of a function exposes the function with its decorated name. For C++ functions, this includes name mangling. For C functions or functions that are declared as extern "C", this includes platform-specific decoration that's based on the calling convention. If you don't want name decoration, use a .def file (EXPORTS keyword).
Here is the result of what I tried with dllexport -
extern "C" __declspec(dllexport) void __cdecl One() {}
extern "C" __declspec(dllexport) void __stdcall Two() {}
extern "C" __declspec(dllexport) void __fastcall Three() {}
«_Superman_»
I love work. It gives me something to do between weekends.
Microsoft MVP (Visual C++) (October 2009 - September 2013) Polymorphism in C
|
|
|
|
|
Oh! So it's the "__stdcall" that was causing the name mangling!
Thanks Uberman!
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Yes, but it is Microsoft specific.
If you'll always use dllimport when invoking functions in the DLL, any calling convention will work as long as it is correctly specified while importing.
«_Superman_»
I love work. It gives me something to do between weekends.
Microsoft MVP (Visual C++) (October 2009 - September 2013) Polymorphism in C
|
|
|
|
|
#include "stdafx.h"
#include "DemoTest.h"
#define MAX_LOADSTRING 100
HINSTANCE hInst; TCHAR szTitle[MAX_LOADSTRING]; TCHAR szWindowClass[MAX_LOADSTRING];
GdiplusStartupInput m_gdiplusStartupInput;
ULONG_PTR m_pGdiToken;
HWND g_hWnd = 0;
Image *g_pImageBack=0;
BLENDFUNCTION g_Blend;
int g_BakWidth, g_BakHeight;
bool isMouseDown=false;
POINT mousePos;
ATOM MyRegisterClass(HINSTANCE hInstance);
BOOL InitInstance(HINSTANCE, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM);
void Update();
int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
GdiplusStartup(&m_pGdiToken,&m_gdiplusStartupInput,NULL);
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine);
MSG msg;
HACCEL hAccelTable;
LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
LoadString(hInstance, IDC_DEMOTEST, szWindowClass, MAX_LOADSTRING);
MyRegisterClass(hInstance);
if (!InitInstance (hInstance, nCmdShow))
{
return FALSE;
}
hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_DEMOTEST));
while (GetMessage(&msg, NULL, 0, 0))
{
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
GdiplusShutdown(m_pGdiToken);
return (int) msg.wParam;
}
ATOM MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_DEMOTEST));
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = MAKEINTRESOURCE(IDC_DEMOTEST);
wcex.lpszClassName = szWindowClass;
wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));
return RegisterClassEx(&wcex);
}
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
HWND hWnd;
hInst = hInstance;
hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
if (!hWnd)
{
return FALSE;
}
g_Blend.SourceConstantAlpha = int(0 * 2.55); g_Blend.BlendOp=0; g_Blend.BlendFlags=0; g_Blend.AlphaFormat=1; g_Blend.SourceConstantAlpha=255; DWORD dwExStyle = GetWindowLong(hWnd, GWL_EXSTYLE);
SetWindowLong(hWnd, GWL_STYLE, dwExStyle ^ WS_EX_TOOLWINDOW);
dwExStyle = ::GetWindowLong(hWnd, GWL_EXSTYLE);
g_pImageBack = Image::FromFile(_T("C:\\Users\\Cmma\\Desktop\\2.png"));
ImageType t = g_pImageBack->GetType();
g_BakWidth = g_pImageBack->GetWidth();
g_BakHeight = g_pImageBack->GetHeight();
g_hWnd=hWnd;
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
Update();
return TRUE;
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;
switch (message)
{
case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
switch (wmId)
{
case IDM_ABOUT:
DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
break;
case IDM_EXIT:
DestroyWindow(hWnd);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
break;
case WM_LBUTTONDOWN:
isMouseDown=true;
GetCursorPos(&mousePos);
ScreenToClient(hWnd,&mousePos);
break;
case WM_MOUSEMOVE:
if(isMouseDown)
{
hdc=::GetDC(hWnd);
Graphics g(hdc);
Pen pen(RGB(255,0,0),3);
g.DrawLine(&pen,0,0,100,100);
::ReleaseDC(hWnd,hdc);
SendMessage(hWnd,WM_PAINT,0,0);
}
break;
case WM_LBUTTONUP:
isMouseDown=false;
break;
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
Update();
EndPaint(hWnd, &ps);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
UNREFERENCED_PARAMETER(lParam);
switch (message)
{
case WM_INITDIALOG:
return (INT_PTR)TRUE;
case WM_COMMAND:
if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
{
EndDialog(hDlg, LOWORD(wParam));
return (INT_PTR)TRUE;
}
break;
}
return (INT_PTR)FALSE;
}
void Update()
{
HDC hdcTemp= ::GetDC(g_hWnd);
HDC hdcMemory=CreateCompatibleDC(hdcTemp);
HBITMAP hBitMap=CreateCompatibleBitmap(hdcTemp, g_BakWidth, g_BakHeight);
SelectObject(hdcMemory, hBitMap);
HDC hdcScreen=::GetDC (g_hWnd);
RECT rct;
::GetWindowRect(g_hWnd, &rct);
POINT ptWinPos={rct.left,rct.top};
Graphics graph(hdcMemory);
Point points[] = { Point(0, 0),
Point(g_BakWidth, 0),
Point(0, g_BakHeight)
};
graph.DrawImage(g_pImageBack, points, 3);
POINT ptDst;
ptDst.x = rct.left;
ptDst.y = rct.top;
SIZE size={g_BakWidth, g_BakHeight};
POINT pt;
pt.x = 0;
pt.y = 0;
DWORD dwExStyle = GetWindowLong(g_hWnd,GWL_EXSTYLE);
if((dwExStyle & WS_EX_LAYERED) != WS_EX_LAYERED)
{ SetWindowLong(g_hWnd, GWL_EXSTYLE,dwExStyle^WS_EX_LAYERED);
}
if (!UpdateLayeredWindow( g_hWnd, hdcScreen, &ptWinPos,
&size, hdcMemory, &pt, 0, &g_Blend, 2))
{
DWORD dwError = ::GetLastError();
printf("failed");
}
graph.ReleaseHDC(hdcMemory);
::DeleteObject(hBitMap);
::DeleteDC(hdcMemory);;
::ReleaseDC(g_hWnd, hdcTemp);
::ReleaseDC(g_hWnd, hdcScreen);
}
|
|
|
|
|
That's an awful lot of code to look through without the ability to compile and test. (You havent included the source of DemoTest.h or resource.rc)
What, specifically, is the problem you're having?
|
|
|
|
|
I want to use #ifdef in my source files to determine if I'm building a 32-bit or a 64-bit executable.
What is the macro I should look for to see if it is a x64 build?
#ifdef x64MACRO
{
64-bit code;
}
#else
{
32-bit code;
}
Thank you.
EDIT:
The answer is "_WIN64". Thanks for reading my post.
The difficult we do right away...
...the impossible takes slightly longer.
modified 22-Nov-13 17:44pm.
|
|
|
|
|
Richard Andrew x64 wrote: What is the macro I should look for to see if it is a x64 build?
Hi,
While _WIN64 will work for windows API... it would be more correct to check for _M_X64 if targeting x86-64.
Best Wishes,
-David Delaune
|
|
|
|
|
Randor wrote: if targeting x86-64
As opposed to? Do you mean ARM or Itanium?
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Hi,
All of the above. There are various Microsoft specific #defines you could utilize when targeting a specific platform:
Predefined Macros[^]
_M_X64 will automatically be defined by the compiler if the target platform is x64. If you are targeting Itanium _M_IA64 is defined by the compiler. etcetera...
Best Wishes,
-David Delaune
|
|
|
|
|
Hi,
I need some quick help on how to make the tree control's background as transparent.
I could achieve similar for setting the dialogbox (CDialog) as transparent.
I have researched alot on this but could-not find a working solution.
Erasebackground,OnCtlColor but they have not worked for the tree control.
Attached is a sample project where this tree control is attached.Expect tree control and the button's I am able to set the transparent dialog as shown in attached snapshot.
Request you to please help me with this issue.
Regards,
Kalyani Homkar
|
|
|
|
|
Hi,
I was unable to attach the sample, but any mfc dialog based sample we can create and add the below code along with a treeview control from resource editor to reproduce it:
OnInitDialog():
SetBackgroundColor(RGB(1,11,21));
LONG ExtendedStyle = GetWindowLong(GetSafeHwnd(),GWL_EXSTYLE );
SetWindowLong(GetSafeHwnd(),GWL_EXSTYLE,ExtendedStyle | WS_EX_LAYERED );
::SetLayeredWindowAttributes(GetSafeHwnd(),RGB(1,11,21),255,LWA_COLORKEY );
Regards,
Kalyani
|
|
|
|
|
In client program ssl_connect(),ssl_write() working fine but ssl_read() is returning SSL_ERROR_ZERO_RETURN. I can't do anything in server program because i am working in Client program.
What i have to do in client program to avoid SSL_ERROR_ZERO_RETURN
error from ssl_read() ?
|
|
|
|
|
Member 10413752 wrote: What i have to do in client program to avoid SSL_ERROR_ZERO_RETURN error from ssl_read() ? Since SSL_ERROR_ZERO_RETURN resvoles to 6 , that means that SSL_read() read 6 bytes from the SSL/TLS connection. Perhaps you meant instead that SSL_get_error() returned SSL_ERROR_ZERO_RETURN .
"One man's wage rise is another man's price increase." - Harold Wilson
"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
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
Hello there,
I am developing an app with CDHtmlDialog that will have a user interface developed in HTML and JavaScript (JS) and CSS.
I am able to make calls from my C++ code to JS. But not sure how i can make calls from JS to C++ code.
Can anyone tell me how to do that?
Any sample code will help.
Thanks in advance.
|
|
|
|
|
I actually want some kind of tool for static analysis of the code, like checkstyle in JAVA.
What i mean by static analysis is, it tells you the coding style error, unused variable and function names
|
|
|
|
|