|
If your library is written in C++, you could declare a global instance of a singleton class. The constructor of that class could initialize the critical section and the destructor would delete it. I am pretty sure the constructor of this class would be called before your progrma is 'running' or at least before most of your other code had a chane to get into trouble.
|
|
|
|
|
Hello all,
I am a C++ newbie, and have what I feel is a fairly simple question....
Basically I have a string of code that when executed in the console gives a list of user id numbers. What I want to do is make a an executable file that will give me a list of the actual user names (found in a lookup table) instead of the user id numbers.
If anyone can give me some advice or point me in the right direction, I would appreciate it. I have tried looking at some articles on this site (Execute a Console Application From VC++) but don't really understand it. Thanks in advance!
Shaun
|
|
|
|
|
What exactly is it that you are wanting to do: 1) execute a console application from VC++ and capture its output, or 2) create an application that will return a name given an id? These are two different things.
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
Okay, basically I'm sharing a floating license for matlab, and want to get a readout of the current user names.
Currently if I open the command prompt and type in a string 'lmutil ... blah blah', it returns a list of user id numbers that are currently using matlab....
What I want to do, is change it to return user names instead of the id numbers. So I thought I could just capture the information from the matlab license checking program (which runs at the command prompt) to retrieve the id number, and then output the cooresponding user names instead.
I wanted to just click on an executable (or batch) file and have it spit out the desired output.
I hope this cleared any confusion, thanks again!
|
|
|
|
|
Two ways to do that:
1.Launch a process that calls your "lmutil ... blah blah" command and that saves the output to a text (Check ShellExecute or CreateProcess in the MSDN or here on CodeProject).
Read the text, and do the substitution.
OR
2.Launch a process that calls your "lmutil ... blah blah" command and that captures the output into a String. [This part is not easy].
Do the substitution in the String.
Have a look at this article[^] to get a start with capturing the output of a process.
Hope this helps
~RaGE();
|
|
|
|
|
|
Dear all,
I'm writing a C++ (.NET 2003 with MFC) application that needs to query several data through WMI. I have a problem while accessing to the "IPAddress" data managed by the Win32_NetworkAdapterConfiguration WMI class.
It is stored as a string array, the first Get returns me this information, but I did not found any issue on how to get the array.
bool CMyDoc::GetWMIItemValue( IWbemClassObject *pInstance,
LPCWSTR pItemName,
CStringArray& strArray)
{
VARIANT val;
LONG lFlavour;
HRESULT hGet;
CIMTYPE cimType;
VariantInit(&val);
strArray.RemoveAll();
hGet = pInstance->Get( pItemName,
0,
&val, // val cannot hold the result
&cimType, // returns 2008 = string array
&lFlavour); // returns 0
if (hGet == WBEM_S_NO_ERROR)
{
if (cimType == (CIM_STRING | CIM_FLAG_ARRAY))
{
// val holds 0x2008 too, unusable
// how can I access the array?
}
}
Thank you for you help...
PS: Using C# is a piece of cake, but my application has been developed in C++ and I cannot convert it.
Daniele
|
|
|
|
|
qrverona wrote:
I have a problem while accessing to the "IPAddress" data managed by the Win32_NetworkAdapterConfiguration WMI class.
I would employ something like:
HRESULT hr;
_variant_t v;
ULONG ulReturned;
DWORD dwAuthLevel;
IWbemLocator *pLocator;
IWbemServices *pService = NULL;
IEnumWbemClassObject *pEnum = NULL;
IWbemClassObject *pClass;
hr = CoCreateInstance(CLSID_WbemLocator, 0, CLSCTX_INPROC_SERVER, IID_IWbemLocator, (LPVOID *) &pLocator);
if (S_OK == hr)
{
hr = pLocator->ConnectServer(_bstr_t(L"root\\cimv2"), NULL, NULL, NULL, NULL, 0, NULL, &pService);
if (WBEM_S_NO_ERROR == hr)
{
hr = CoQueryProxyBlanket(pService, NULL, NULL, NULL, &dwAuthLevel, NULL, NULL, NULL);
hr = CoSetProxyBlanket(pService,
RPC_C_AUTHN_DEFAULT,
RPC_C_AUTHZ_NONE,
NULL,
dwAuthLevel,
RPC_C_IMP_LEVEL_IMPERSONATE,
NULL,
EOAC_NONE);
hr = pService->CreateInstanceEnum(_bstr_t("Win32_NetworkAdapterConfiguration"),
WBEM_FLAG_RETURN_IMMEDIATELY | WBEM_FLAG_FORWARD_ONLY,
NULL,
&pEnum);
if (WBEM_S_NO_ERROR == hr)
{
do
{
hr = pEnum->Next(WBEM_INFINITE, 1, &pClass, &ulReturned);
if (WBEM_S_NO_ERROR == hr)
{
hr = pClass->Get(L"IPAddress", 0, &v, NULL, NULL);
if (v.vt != VT_NULL)
...
pClass->Release();
}
} while (WBEM_S_NO_ERROR == hr);
}
}
}
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
Hi
I have a simple dialog based MFC application which I have developed using CBannerStatic project available here at "http://www.codeproject.com/staticctrl/bannerstatic2.asp#xxxx"
Here when I make my font size very big, the banner gets very slow and stucks sometime when I have more load on my CPU by some other application running
Is there a way to give some amount of CPU to only my Banner application or is there a way to assign some value through which Banner doesn't gets affected because other running application ?
Thanking you.
Amarelia Maehsh
Gujarat
India
|
|
|
|
|
Please quit posting the same question in the wrong forum multiple times.
John
|
|
|
|
|
Hello,
You could try the following:
::SetPriorityClass(::GetCurrentProcess(), ABOVE_NORMAL_PRIORITY_CLASS);
IMHO you should not change your process priority for reasons like this. If the user has a high CPU load, he or she is doing something important most of the time. The user would get very annoyed if your banner will consume more CPU than the users 'important' processes.
Behind every great black man...
... is the police. - Conspiracy brother
Blog[^]
|
|
|
|
|
Hi Bob
Thankx a lot to give kind attention to my question
I tried but it gives error at compile time if i use ABOVE_NORMAL_PRIORITY_CLASS flag, Instead if i use HIGH_PRIORITY_CLASS it works but it takes all the CPU and takes too long time to execute other processes....
What seems to be the reason that it gives error for ABOVE_NORMAL_PRIORITY_CLASS ? The error is :
"error C2065: 'ABOVE_NORMAL_PRIORITY_CLASS' : undeclared identifier"
Any idea what to do ?
Thankx
Amarelia Maehsh
Gujarat
India
|
|
|
|
|
Amarelia wrote: What seems to be the reason that it gives error for ABOVE_NORMAL_PRIORITY_CLASS ? The error is :
"error C2065: 'ABOVE_NORMAL_PRIORITY_CLASS' : undeclared identifier"
Are you on a Windows 2000 or XP machine? What is the value of _WIN32_WINNT ?
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
Hi David
I am using Windows 2000
And not getting what do you mean by ,"What is the value of _WIN#@_WINNT?"
Thankx
Amarelia Maehsh
Gujarat
India
|
|
|
|
|
Amarelia wrote: And not getting what do you mean by ,"What is the value of _WIN#@_WINNT?"
I was going to suggest that it had to be greater than or equal to a certain value, but after looking in winbase.h, I see that is not the issue. I can only suggest that you verify the spelling of ABOVE_NORMAL_PRIORITY_CLASS .
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
Hi
Amarelia Maehsh
Gujarat
India
|
|
|
|
|
Hi
Amarelia Maehsh
Gujarat
India
|
|
|
|
|
Good day,
How can I make transparency in CBitmapButton. I dont want to display image part with color RGB(255,0,255).
Thanks.
|
|
|
|
|
hi, everybody,
I create a WebBrowser control in a dialog, then i get a pointer to CWebBrowser2 which is named m_pBrowser, after that i use the "navigate2" to open some site. As the pages of the site contains many pictures, so the m_pBrowser alloc memory itself to get and display the HTML page.
but , after i use "m_pBrowser->DestroyWindow()" and "delete m_pBrowser" to destroy the control, m_pBrowser disappeared but the memory which was alloced by itself could not be freed. And the sizeof these memories is large, always larger than 20M.
How could i free these memories manual?
Thank all of you very much!!!
PS: i used the codes blow to create a WebBrowser control :
m_pBrowser=new CWebBrowser2;
m_pBrowser->Create("",WS_CHILD|WS_VISIBLE,rt,this,9000);
m_pBrowser->SetRegisterAsBrowser(FALSE);
m_pBrowser->SetSilent(TRUE);
m_pBrowser->ShowWindow(SW_SHOW);
|
|
|
|
|
Hello everybody,
Does anyone know ho can I terminate the sqlservr.exe process?
I tried the TerminateProcess() but it didn't work and I guess that it must be the child processes or threads that might be running with it.
So how can I terminate all the tree process?
Thanks in Advance!
sirtimid
|
|
|
|
|
sirtimid wrote:
I tried the TerminateProcess() but it didn't work...
Which means nothing unless you tell us why it failed? What does GetLastError() return?
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
This is the process that the MSSQLSERVER runs.
It returned 6 (The handle is invalid. - ERROR_INVALID_HANDLE)
I got the Process ID as shown below:
HANDLE hProcessSnap = NULL;
BOOL bRet = FALSE;
PROCESSENTRY32 pe32 = {0};
hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if (hProcessSnap == INVALID_HANDLE_VALUE)
return FALSE;
pe32.dwSize = sizeof(PROCESSENTRY32);
if (Process32First(hProcessSnap, &pe32)) {
DWORD dwPriorityClass,excd;
BOOL bGotModule = FALSE;
bool found = false;
MODULEENTRY32 me32 = {0};
do {
HANDLE hProcess;
hProcess = OpenProcess (PROCESS_ALL_ACCESS | PROCESS_TERMINATE | PROCESS_QUERY_INFORMATION,
FALSE, pe32.th32ProcessID);
if(!memcmp(pe32.szExeFile,"sqlservr.exe",12)) {
bGotModule = GetExitCodeProcess(hProcess, &excd);
TerminateProcess(hProcess, excd);
err = GetLastError();
found = true;
} else {
found = false;
}
CloseHandle (hProcess);
} while (Process32Next(hProcessSnap, &pe32) && !found);
}
CloseHandle (hProcessSnap);
|
|
|
|
|
sirtimid wrote: hProcess = OpenProcess (PROCESS_ALL_ACCESS | PROCESS_TERMINATE | PROCESS_QUERY_INFORMATION,
FALSE, pe32.th32ProcessID);
if(!memcmp(pe32.szExeFile,"sqlservr.exe",12)) {
Shouldn't you be checking the return value from OpenProcess() before attempting to call memcmp() ?
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
It is probably a service that can be shutdown using the service manager.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
Hi
I have used the BannerTester project given at
http://www.codeproject.com/staticctrl/bannerstatic2.asp
Here when I increase the size of the Font, it becomes very very slow speed.
I want to increase the speed of the text...is there any idea how to achieve it ?
Regards,
Mahesh
Amarelia Maehsh
Gujarat
India
|
|
|
|