|
LPCTSTR data = L"0\0";
LONG setRes = RegSetValueEx (hKey, value, 0, REG_DWORD, (LPBYTE)data, 1);
You are storing a Unicode string instead of an integer. The data should be a DWORD containing either 0 or 1 , like:
DWORD data = 0;
LONG setRes = RegSetValueEx (hKey, value, 0, REG_DWORD, (LPBYTE)&data, sizeof data);
Veni, vidi, abiit domum
|
|
|
|
|
Hi,
I am using WNetGetConnection() API to check that my network drive(mapped to a local share folder) is connected or not. When i run this application as run as administrator with UAC enabled, this API return success even if n/w drive is disconnected. Its works fine when i run application without admin privilege( standard user). Anybody got the same issue?
Any help or guidance would be appreciated.
Sample code
LPTSTR lpszDeviceName = 0;
lpszDeviceName = new TCHAR[ 256];
DWORD dwcchBuff = MAX_PATH;
DWORD dwResult = 0;
dwResult = WNetGetConnection( _T("Z:"), lpszDeviceName, &dwcchBuff );
if( NO_ERROR != dwResult )
{
printf("Media removed\n");
}
else
{
printf("Media inserted\n");
}
|
|
|
|
|
On my machine, the code seems to be working properly in both the scenario. Please ensure that you've not set user specific rights to the locally shared folder.
|
|
|
|
|
Hi,
Thanks for your reply.
Hmm.. I have just shared the folder( permission to everyone i think). The problem is still exists when UAC is enabled( my UAC settings is default) and I run application as admin. Its works fine when UAC is disabled( i.e Never notify).
Thanks
Arun
|
|
|
|
|
I would like to output three columns of numbers with the decimal points lined up. I wrote the following piece of code which I thought would do it.
for( int i = 0; i<100; i++ ) {
double f1 = (int)(i/20);
double f2 = 3.1415*i;
double f3 = 3.1415*(f2+3);
cout.width( 10 );
cout.precision( 4 );
cout << std::left << f1 << " ";
cout.width( 10 );
cout << std::left << f2 << " ";
cout.width( 10 );
cout << std::left << f3 << endl;
}
However, the decimal points are not lined up. Also, I want to do this in C++ not C. That is, I do not want to use, printf, fprintf or sprintf. How do I get the decimal points to line up vertical?
Thanks
Bob
|
|
|
|
|
Check if this is helpful.
{
cout << fixed;
for( int i = 0; i<10; i++ ) {
double f1 = (int)(i/20);
double f2 = 3.1415*i;
double f3 = 3.1415*(f2+3);
std::cout << std::setfill (' ') << std::setw (10);
cout.width( 10 );
cout.precision( 4 );
cout << f1 << " ";
cout.width( 10 );
cout << f2 << " ";
cout.width( 10 );
cout << f3 << endl;
}
getch();
}
|
|
|
|
|
Thanks for the response. However, it failed to produce the results I wanted. Here is part of the output that I got:
0 0 9.425
0 3.142 19.29
0 6.283 29.16
0 9.425 39.03
0 12.57 48.9
0 15.71 58.77
The decimal points are not lined up. What I want is:
0 0.0 9.425
0 3.142 19.29
0 6.283 29.16
0 9.425 39.03
0 12.57 48.9
0 15.71 58.77
In what I want the decimal points are all in the same column.
|
|
|
|
|
But at my end I'm getting proper output.
Have a look at this[^].
|
|
|
|
|
Have you tried removing std::left ?
"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
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
I tried it with std::left, without std::left and with std::right. In all three cases it did not work. What I believe the problem is that there is no way to specified a fixed number of digits along with a fixed number of digits to the right of the decimal point. I think I am going to go use sprintf and then send the output the string sprintf produces. It is not the "C++ way" of doing things but it works.
I want to thank the group for their responses.
Bob
|
|
|
|
|
Try adding cout << setiosflags(ios::fixed) right before the for() loop.
"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
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
David,
Adding the line:
cout << setiosflags(ios::fixed);
before the for loop did the trick. The program now works as expected. I am
happy.
I thank you and all the other people who responded to my post for their help in this matter.
Bob
|
|
|
|
|
I have an application that randomly displays images on a screen. There's a capture button, and when user clicks on that button, the image that is currently displayed is stored into a buffer.
User can click the button 5 times. i.e., the buffer should be storing upto 5 image data.
I have code like this,
.h File:
unsigned char* m_ImageBuffer[5];
.cpp File:
while (1)
{
----------
----------
m_ImageBuffer[counter] = new unsigned char[size];
memcpy(m_ImageBuffer[counter], pImageData, size);
----------
----------
}
The variable "counter" goes from 0 to 4. Inside the WHILE loop a bunch of images are constantly displayed
in the screen.
The purpose of m_ImageBuffer is that, i will store the user selected image data in this buffer, so that it could be later used for display. i.e., in a different screen.
The problem with the code in WHILE loop is that, i am not able to use DELETE properly. So the code logic basically ends up eating so much memory.
I am looking for a better logic, by which i can store the image data, but still does better memory management.
Not sure the problem is explained properly. I am expecting some suggestions on how to manage this situation.
Thanks in advance.
|
|
|
|
|
At the beginning of the program initialise the buffer so all pointers are NULL. Then every time you save an image, check if the pointer is not null and if so delete[] it. Something like:
if (m_ImageBuffer[counter] != NULL)
delete[] m_ImageBuffer[counter];
m_ImageBuffer[counter] = new unsigned char[size];
memcpy(m_ImageBuffer[counter], pImageData, size);
Veni, vidi, abiit domum
|
|
|
|
|
Proper c++ memory management would tell you to use standard c++ classes and collections instead of arrays and pointers to data.
Change the array to either a std::vector or a std::array (if c++11).
If possible I would replace the unsigned char* with a proper image class (if on Windows, CImage, CBitmap, ... )
If you need something portable and want to keep the unsigned char* , create a wrapper class around it with proper constructor/destructor/copy/assignment methods.
I'd rather be phishing!
|
|
|
|
|
Maximilien wrote: Proper c++ memory management would tell you to use standard c++ classes and collections...
None those suggestions however would fix the problem of increasing memory usage. Where the first response does.
|
|
|
|
|
Apart from the solution that Richard has given, I'd like to suggest you to go through the code snippet from WHILE block and ensure that the array index variable 'counter' is increased properly whenever an image is selected. Because, looking at the code snippet you gave, the index variable 'counter' is not incremented immediately after allocation index element (or you didn't include that part while pasting the code).
Looking at the logic you explained, it seems that you may not be deleting the image data in the while loop. Or are you?
If the user has the choice of deselecting the image, you should be able to delete the respective indexed image item, and should maintain the empty slot index data. That involves extra bookkeeping.
I would suggest to give a try using STL container classes. For that, this[^][^] may help you.
If possible, provide the full WHILE loop code snippet. That will help to find out memory leak (as your app is ending up much memory).
|
|
|
|
|
<pre><pre lang="text">
I can specify relative path from current directory using “Additional include directories “ to a directory on same level and it compiles. Same method works when “going up” in directory tree.
Additional include directories ( for compiler )
.\TESTLib
#include "..\_TEST.h"
#include "..\StdAfx.h"
Now how do I specify the path to a subdirectory?
My directory “Modules” is on same level as project directory and “DIrectShow 8.1 SDK” is its
subdirectory.
This does not work, obviously I am missing something.
Additional include directories
.\Modules\DIrectShow 8.1 SDK
#include "..\Modules\DIrectShow 8.1 SDK\_TEST_B.h"
Any help or reference source / sample would be greatly appreciated.
Cheers Vaclav </pre></pre>
|
|
|
|
|
Ive always avoided specifying '3rd party' SDK's like that
What I usually do, is set a System Environment Variable with the path to the SDK eg DIRECTSHOW -> {whatever}\Modules\DirectShow 8.1 SDK\ , then use $(DIRECTSHOW)\_TEST_B.h in the compiler/link options
The reason or this is, if I then need to change the version of DirectShow, I can do that without frigging around with the project (I just change the environment variable)
Im sorry that this doesn't actually answer your question
|
|
|
|
|
Maybe this will work?
#include "Modules\DIrectShow 8.1 SDK\_TEST_B.h"
|
|
|
|
|
Yes, that works, I used it for test, but I need to specify common path for the rest of the includes. That is why it is in " Addtional include " settings.
The "problem " is I do not know how to access directories not in direct "up" path from the main (project) directory.
And to be honest, I kinda forgot how to do "system" variables. I guess I need to brush up on DOS.
|
|
|
|
|
You can specify the parent of a parent directory like so: ..\..\Parent\SubDir
You can put as many ..\ together as you need to back up to the common parent directory.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Additional include directories
.\Modules\DIrectShow 8.1 SDK
#include "..\Modules\DIrectShow 8.1 SDK\_TEST_B.h"
Do you see why that makes no sense? You have told the compiler to look in .\Modules\DIrectShow 8.1 SDK , that is to say, two subdirectories below the current one. You then give a different path in your #include statement, which says that the Modules directory is a sibling of the current one. If you add the paths in your project settings then you don't need to add them in your #include statements.
Veni, vidi, abiit domum
|
|
|
|
|
I do not think I was very clear in my post.
What I need is to build a common "include path".
I need to tell the compiler how to get from this full directory path:
D:\0\00 Video\Library\StaticLibrary\WebCam - from project WebCam
to streams.h file in this full directory path:
D:\0\00 Video\SDK\DIrectShow 8.1 SDK\samples\Multimedia\DirectShow\BaseClasses\streams.h
I need this path because there are other includes in streams.h
In my foolish way of thinking - I need to go up two levels to common 00 Video directory and than down 5 levels. I relatively know how to "go down ..\" but have no clue how to "go up".
Is that even possible?
|
|
|
|
|
Hi,
Vaclav_Sal wrote: What I need is to build a common "include path".
If you take advantage of the Macros for Build Commands and Properties[^]; based on your two paths I think you would this to your 'Additional Include Directories' :
$(ProjectDir)\..\..\..\SDK\DirectShow 8.1 SDK\samples\Multimedia\DirectShow\BaseClasses\
Note that $(SolutionDir) is the path to the solution file (*.SLN) and $(ProjectDir) is the path to the project file (*.vcproj || *.vcxproj)
Best Wishes,
-David Delaune
|
|
|
|