|
That's the way I would expect it to work, but I'm sure not seing that in that uncompilable code
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Never mind. I missed this...
Glenn Sandoval wrote: In WinNT.h, around lines 939:
Which led me to the missing code
Cheers,
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Glenn Sandoval wrote: Can anyone explain this in terms mere mortals can understand?
i think the following is too descriptive for mere mortals.
Glenn Sandoval wrote: I found this magical bit of code that will give the number of elements in an array without knowing it's type.
I can see three magics. 1 ) one taking advantage of sizeof(char) as 1, 2)taking advantage of const parameter in template declaration to deduce the size of array.
3) sizeof() operator only bothers type, it won't execute function
Glenn Sandoval wrote:
template <typename T, size_t N>
char (*RtlpNumberOf( UNALIGNED T (&)[N] ))[N];
#define RTL_NUMBER_OF_V2(A) (sizeof(*RtlpNumberOf(A)))
1) use of sizeof(char)
(*RtlpNumberOf(A)) effectively has the return type as the charater array type with the equal number of elements that of the Array passed, since sizeof (char) is 1, the sizeof (character array) will be the number of elements.
ie; if you pass <array of anytype>[128], then return type of RtlpNumberOf is char(*)[128], so sizeof(* char(*)[128]) = sizeof(char[128]) = 128 * sizeof(char) = 128
char (*function())[10]; function returning pointer to character array(as function cannot return array so pointer to array)
sizeof(*function()) = sizeof(*char(*)[10]) = sizeof(char[10]) = 10 * sizeof(char) = 10;
// note sizeof operator uses dereferenced return type. (*function())
2) use of const parameter in template
template <size_t N>
void func(char (&arr)[N]);
here the constant parameter N is deduced to number of element of array.
so char cArray[128]; func(cArray) will deduce N as 128;
putting it togetter,
template <typename T, size_t N>
char (*func(T (& )[N]))[N]
func has return type char (*)[N] which sizeof() operator considers.
3) use of sizeof() operator won't execute function.
So definition of function is not needed. at the point of template instantiation, N is deduced to the number of element of array, function is not executed, returns the number of elements.
advantage
advantage of this over sizeof(array)/sizeof(array[0]) is,
1) unnamed struct cannot be used.
2) pointer which may not be an array cannot be used.
modified on Friday, March 7, 2008 10:11 AM
|
|
|
|
|
Rajkumar R wrote: advantage of this over sizeof(array)/sizeof(array[0]) is,
1) unnamed struct cannot be used.
2) pointer which may not be an array cannot be used.
Thanks, that was going to be my next question.
I appreciate all the great responses. I think I understand now.
|
|
|
|
|
I am trying to invoke a Win32 DLL from the Windows Installer to perform certain custom actions.
For this purpose I have exposed 1 API
MY_DLL_API UINT MyCustomActionLaunch(MSIHANDLE hMsiModule)
{
MessageBoxW (NULL, L"MyCustomAction launch", L"MyCustomAction", MB_OK);
WCHAR msg [500] = {0};
WCHAR vbuff [1024] = {0};
DWORD vlen = 1024;
UINT gp = MsiGetPropertyW(hMsiModule, L"ProgramFilesFolder", vbuff, &vlen);
if(gp == ERROR_SUCCESS )
{
if (wcslen(vbuff) <= 0)
{
<big> MessageBoxW(NULL , L"Zero Bytes",L"MyCustomAction" , MB_OK);</big> }
MessageBoxW(NULL, vbuff, L"MyCustomAction", MB_OK);
} else
{
MessageBoxW (NULL, L"Failure", L"MyCustomAction", MB_OK);
}
return -1;
}
I find that no bytes are being copied, where I am querying for a standard property .
This DLL is being developed in VC6.
Does anyone see anything wrong here ?
Engineering is the effort !
|
|
|
|
|
Hello,
i'm trying to code a small encryption application, which encrypts files with different algorithms. i'm using crypto++ lib for the encryption part, and qt for the gui part. now after struggling with the encryption for a while, i found an example via google that i'm using now to encrypt files. its like this:
const char* CrypThread::EncryptAes(const char* inputFileName, const char* outputFileName, const char* password)<br />
{<br />
byte pass[AES::BLOCKSIZE]; <br />
byte iv[16]; <br />
byte true_iv[16]; <br />
<br />
AutoSeededRandomPool rng;<br />
<br />
try <br />
{ <br />
StringSource(password, true, new HashFilter(*(new SHA256), new ArraySink(pass, AES::BLOCKSIZE)));<br />
<br />
rng.GenerateBlock(iv, 16);<br />
memset(true_iv, 0, 16);<br />
<br />
AES::Encryption aesEncryption(pass, CryptoPP::AES::DEFAULT_KEYLENGTH);<br />
CFB_Mode_ExternalCipher::Encryption cbcEncryption(aesEncryption, iv, 8);<br />
<br />
StreamTransformationFilter *encryptor;<br />
<br />
encryptor = new StreamTransformationFilter(cbcEncryption, new FileSink(outputFileName));<br />
encryptor->Put(iv, 16);<br />
<br />
FileSource(inputFileName, true, encryptor);<br />
}<br />
catch(CryptoPP::Exception &e)<br />
{<br />
return e.what();<br />
}<br />
<br />
return 0;<br />
}
While the encryption seems to work (i admit that i dont really know what i'm doing..), i was wondering if there is any way to monitor encryption progress. i want to implement a progress bar in the program, so you can see how far your 2gb file is encrypted already. my current idea is to watch the destination file with a QFileSystemWatcher, and set the current size of the destination file as progress. this would probably work, however the file size of the destination file stays 0 until the encryption is finished, even if the file is quite large.
is there any way to have crypto++ stream the encryption right to the hdd, so the file size grows?
if not, maybe someone has an idea of how to implement a progress-monitor function? in the application, the main thread runs the gui stuff, whereas the encryption is done in a separate thread.
also, since i'm still having issues with crypto++, anyone knows a site thats showing examples with file encryption?
tia for any help
|
|
|
|
|
Hi All,
I have an ActiveX control. And the event map is defined in the control's implementation (.CPP) file.
Say the event map has a function
EVENT_CUSTOM("SomeEvent", FireSomeEvent, VTS_BOOL)
defined in it...
Now I can very easily call the function 'FireSomeEvent' from the control's implementation cpp file.
Can I call 'FireSomeEvent' from some other cpp file....means some other's class's code ??
If yes then how??
Urgent help needed...
Thanks and Regards,
AbbyIndian
...A Programmer may or may not be the master of the programming language grammar...
|
|
|
|
|
As long you have a reference of this class and the member is public...you should.
God bless,
Ernest Laurentin
|
|
|
|
|
Is it possible to place an activex control on a dialog box of a DLL. When I try to do this the dailog box does not show up. The activex shows on on the dialog box of an exe just fine.
I am assuming that you need to do something different when working with DLLs.
Thanks,
Deelip Menezes
|
|
|
|
|
Make sure you call CoInitialize(NULL) in your app. It doesn't matter it's inside of a DLL.
God bless,
Ernest Laurentin
|
|
|
|
|
Just tried that. Did not work. I put CoInitialize(NULL) in the CWinApp constructors of the DLL as well as the EXE. Am I doing something wrong?
I am usign VC 6.0 and when making the AppWizard generated DLL I checked the Automation box. So it should already be set up to run ActiveX controls.
Any ideas?
Deelip Menezes
|
|
|
|
|
Hi,
I have a Windows App/process that consists of one exe and a bunch of DLL's
In of othe DLL's I allocate a object via the "new" operator and save the pointer to it
in a sturcture which is part of another DLL
later on a exported function in my DLL gets invoked from one of the DLL's in the app
only to find this pointer has a value of NULL
My question is.. Is storage for an object allocated via the "new" operator gone once the code in the DLL finishes executing even though the DLL is in core
If so is it possible to allocate storage for an object and have it remain in storage for the life of the DLL
|
|
|
|
|
ForNow wrote: My question is.. Is storage for an object allocated via the "new" operator gone once the code in the DLL finishes executing
What do you mean with the above? Are you run-time linking (i.e. with LoadLibrary ) with such DLL and then calling FreeLibrary ?
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
|
|
|
|
|
No implicit linking
Dll a links to dll b via function call
Dll b creates obtjects via new operator stores pointer at dll d (structure that was exported)
Dll e calls dll b via function call and dll b tries to retrive the pointers from the structure that was exported but the value is zero
I was wondering what is the duration of storage allocated via the
"New" operator
|
|
|
|
|
ForNow wrote: I was wondering what is the duration of storage allocated via the
"New" operator
Should be until correnponding cleanup happens(i.e. delete call) hence it should stand well-alive until your process ends.
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
|
|
|
|
|
Maybe I'll put the pointer under "Watch" and see when it disappears
Thankx
|
|
|
|
|
i know this has been done, ive seen examples i just cant seem to figure it out, how if at all can i create an object outside the form, say on the desktop? any help is appreciated, thanks. Oh i use Borland if that helps any...
|
|
|
|
|
codeinelogic wrote: say on the desktop?
Try using the window handle of the Desktop as the parent window to the window you are creating.
led mike
|
|
|
|
|
If you need to paint outside the application window use a screen device context (obtained via GetDC(NULL) ).
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
|
|
|
|
|
I have written an application using Visual Studio 6 C++, targeted for Windows XP and 2000. How do I detect/prevent multiple instances of my program?. I only want a single instance running and every time I click the shortcut, I get another instance launched (Duh!).
|
|
|
|
|
I use this:
CreateMutex(NULL, TRUE, _T("Unique_String_Identifying_The_Application"));
if (GetLastError() == ERROR_ALREADY_EXISTS)
{
return;
}
You can place this code in InitInstance() for example.
|
|
|
|
|
Works like a charm.. (as if you needed me to tell you)
Thanks!
|
|
|
|
|
|
Michael,
Not everything Dr. Newcomer has written is correct in that article. He fails to mention the Global Local and Session namespace types of kernel objects.
http://msdn2.microsoft.com/en-us/library/aa382954(VS.85).aspx[^]
I find that some of his articles fail to address features of modern operating systems such as Vista and even some features of XP. If the goal of the original poster is to limit his application to an absolute single instance then the above code is perfectly sufficient by simply declaring the Mutex as global.
By adding a prefix of "Global\\" to the Mutex there is absolutely no way another instance of the application will be created. In addition, if you look at the bottom of the article by Dr. Newcomer he presents large functions to limit the application to session and global both of which can be achieved by simply prefixing the Mutex with "Global\\" , "Local\\" or "Session\\".
Conversely, if the goal of the original poster is to have maximum flexibility then perhaps the code Dr. Newcomer has presented would be better. Although I would personally modify it to use the kernel object namespaces.
Best Wishes,
-David Delaune
|
|
|
|
|
Randor wrote: Not everything Dr. Newcomer has written is correct in that article.
Incorrect or just outdated?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"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
|
|
|
|