|
Hi,
you use the rand() function like this:
2500-500= 2000
rand()%2001 //a number between 0 and 2000
rand()%2001 +500 // a number between 500 and 2500
Regards
|
|
|
|
|
Hi all,
i inherite a call of my own from CPreviewView. i put my own toolbar there,
problem is the default implementation of CPreviewView draws a dialog bar with Toolbar in it...how can i remove this default option?
thanks
Yaron Nir
Ask not what your application can do for you,
Ask what you can do for your application
|
|
|
|
|
I have not idea what to do if i want to make security in my program so that one user can open these forms and not others.
When I was programed in Access, i had a global variable where I want to put the user name from there i want to test if he had right or not, But with Visual c++ there is not global variable(i do know if it is possible to have it) what to do ?
I learn my self
|
|
|
|
|
There is global variables in C/C++ too, but it isn't considdered to be good programming practice to use it.
Use it like this:
In source1 (declaration + use)
char GlobalCharArray[100];
int GlobalInt;
In source2 (use):
extern char GlobalCharArray[100];
extern int GlobalInt;
Now you use the same char array and int from both source-codes.
|
|
|
|
|
Good, There is not link source1 and source 2.
In source2 can I insert the header file of source1 ? like below
#include "source1.h"
|
|
|
|
|
Sorry that I was a bit unclear.
When I said "source1" I meant the source file sourcecode1.cpp
And Sourececode2.cpp
I wanted to show you how to use the same global variable in two different source-files.
If you got only one source file, declare it the way I suggested in "source1", and then, just use it from wherever in that source-file.
Good luck.
kakan
|
|
|
|
|
Hi!
When I use DeviceIoControl() to communicate with a special
device in my VC++ application,the DeviceIoControl() returns
zero,and the Getlasterror() returns 50.
I defined an IOCTL command in my driver,and used CreateFile to retrieve the device handle.
I set a breakpoint at IRP dispatch instance in my driver code with SoftICE,
but it seems that the DeviceIoControl() can not communictate with the driver.
What's the matter then?
Thanks for help!
momer
-- modified at 2:03 Tuesday 20th September, 2005
|
|
|
|
|
Did you use open, start, stop and close device driver (sys) dinamicly? It is look like driver not started.
|
|
|
|
|
Hi!Branislav,
Before use DeviceIoControl() I have used the CreateFile() to retrieve the device handle,and I suppose the CreateFile() can open the device driver.
And I can know that the CreateFile() resposes by the IRP_MJ_CREATE with SoftICE,so I think the device driver (sys) has been opened before the
application runs to DeviceIoControl().
Thanks!
momer
|
|
|
|
|
Before use any function to call driver you must start driver service if you did not have automatic start during instalation driver. For more details see
http://www.l5sg.com/products/source_code.php
source code for tipical install, start and stop a service or driver. You can use that code to open and start driver before call CreateFile, ... and after, before the end of your program, close service or driver.
All you can check in Administrative Tools\Services. And most important thing is that you must be Administrator or privelege level like administrator.
|
|
|
|
|
Hi!Branislav,
Yes.My device is an USB vedio capture and the driver is a streaming minidriver,so when I plug the device into pc,the pnp manager can load and install the minidriver automaticly and then the I/O manager start the minidriver.In fact,as long as the vedio capture device plug into pc,my minidriver begins capturing vedio and audio data from the usb bus.So,I believe that the driver have been started before my calling CreateFile.
And,every time the application runs to CreateFile,the SoftICE tells me that the minidriver have recieved a SRB,which is SRB_UNKNOWN_DEVICE_COMMAND.
Thanks for help!
momer
|
|
|
|
|
Hi all,
I need to allow clients instant access to the error-checking section of the local hard drives property page (tools tab).
In ME I used to just startup scandisk.exe and clients could select which drives and perform a scan but XP doesn't have scandisk.exe.
Does anyone know how to access this in code?
Even if I could directly bring up the tools tab of the local disk properties window.
Jai
|
|
|
|
|
|
thanks Branislav,
sysinternals looks like an interesting site.
jai
|
|
|
|
|
Hi,
I am invoking my mail client using following piece of code. The code opens the mail client having a subject and a file attached with it.
Note: Following piece of code is written in java, i hope the same follows for vc also.
String strLicensePath = "c:\\rohit.txt";
try {
Runtime.getRuntime().exec(
new String[] {"rundll32", "url.dll,FileProtocolHandler",
"mailto:" + "&subject=" + "TEST_STRING" +
"&attachment=" + "\""+ strLicensePath + "\""}
);
}
catch (Exception ex) {
ex.printStackTrace();
}
The above code works fine on my machine having "Microsoft Outlook 2000 SP-3" installed. But gives following error on machine having
Microsoft Outlook 2002 installed:
"The command line argument is not valid. Verify the switch you are using."
Also, the problem is coming in some of other machines also.
Am I using wrong switches, i.e. arguments??
Or is there any alternative way to achieve the same. Please comment.
|
|
|
|
|
Hi,
Can I attach binary data to the http stream ?
As I know, for our sending binary data, we need to encode it by base64,
but it will lead to larger data size for transfer, so can I directly
attach binary data to the http stream ? Does the http specification
allow it ? And will it be blocked by firewall ?
Thanks
|
|
|
|
|
The http headers of the response specify the content-type and encoding of the body, which according to them, can be binary. In fact, that's how files are usually downloaded (e.g., .exe, .zip, .jpg).
For example, the following are the headers of the http response after submitting a GET for http://www.codeproject.com/images/standard/logo225x72.gif:
Server: Microsoft-IIS/5.0
X-Powered-By: ASP.NET
Cache-Control: max-age=86400
Expires: Wed, 21 Sep 2005 03:57:21 GMT
Connection: close
Date: Tue, 20 Sep 2005 03:57:21 GMT
Content-Type: image/gif
Accept-Ranges: bytes
Last-Modified: Fri, 16 Nov 2001 00:10:57 GMT
ETag: "f076372a336ec11:8b1"
Content-Length: 5826
After those headers comes the response, which in this case is binary data (i.e., 5826 bytes)
--
jlr
http://jlamas.blogspot.com/[^]
|
|
|
|
|
So this is the first time I'm doing anything more complex with CryptoAPI than a MD5 hash, and in typical MS fashion the API is over-complex and under-documented. Anyhoo, I'm trying to generate a public/private key pair so I can ship the public key in an app and write an encrypted log file (the thinking being that only my log viewer will have the private key so no one else could read sensitive data in the log). Problem is, I'm able to encrypt and decrypt using just the public key. WTF?
Here's how I created the keys. Error handling has been omitted here but all calls are succeeding in my test app.
HCRYPTPROV hcp;
HCRYPTKEY hcc;
if ( !CryptAcquireContext ( &hcp, NULL, MS_ENHANCED_PROV, PROV_RSA_FULL, 0 ) &&
GetLastError() == NTE_BAD_KEYSET )
{
CryptAcquireContext ( &hcp, NULL, MS_ENHANCED_PROV, PROV_RSA_FULL, CRYPT_NEWKEYSET ) )
}
<font color=red>
CryptGenKey ( hcp, CALG_RSA_KEYX, (4096<<16)|CRYPT_EXPORTABLE, &hcc );
DWORD cbyBlob = 0;
BYTE* pbyPublicBlob = NULL, *pbyPrivateBlob = NULL;
CryptExportKey ( hcc, NULL, PUBLICKEYBLOB, 0, NULL, &cbyBlob );
pbyPublicBlob = new BYTE[cbyBlob];
CryptExportKey ( hcc, NULL, PUBLICKEYBLOB, 0, pbyPublicBlob, &cbyBlob );
CryptExportKey ( hcc, NULL, PRIVATEKEYBLOB, 0, NULL, &cbyBlob );
pbyPrivateBlob = new BYTE[cbyBlob];
CryptExportKey ( hcc, NULL, PRIVATEKEYBLOB, 0, pbyPrivateBlob, &cbyBlob );
That's all fine and dandy and I end up with two byte arrays:
BYTE abyPublicKey[] = { ... };
BYTE abyPrivateKey[] = { ... }; So now when I test importing just the public key, I can do this:
HCRYPTKEY hpubkey;
CryptImportKey ( hcp, abyPublicKey, sizeof(abyPublicKey), NULL, 0, &hpubkey );
BYTE thetext[] = "The Code Project", *pbyBuffer = NULL;
DWORD cbyPlainText = sizeof(thetext), cbyCipherText = 0;
CryptEncrypt ( hpubkey, NULL, TRUE, 0, NULL, &cbyCipherText, cbyPlainText );
pbyBuffer = new BYTE[cbyCipherText];
memcpy ( pbyBuffer, thetext, cbyPlainText );
CryptEncrypt ( hpubkey, NULL, TRUE, 0, pbyBuffer, &cbyPlainText, cbyCipherText );
BYTE* pbyDecrypted = new BYTE[cbyCipherText];
memcpy ( pbyDecrypted, pbyBuffer, cbyCipherText );
<font color=red></font>
CryptDecrypt ( hpubkey, NULL, TRUE, 0, pbyDecrypted, &cbyCipherText ); The same public key results in successful calls to CryptEncrypt() and CryptDecrypt() . So either I'm doing something dumb (which is possible, I'm not used to this API yet) or I didn't really get a pub/private key pair from CryptGenKey() . Any ideas?
--Mike--
Visual C++ MVP
LINKS~! Ericahist | 1ClickPicGrabber | NEW~! CP SearchBar v3.0 | C++ Forum FAQ
Pinky, are you pondering what I'm pondering?
I think so Brain, but how will we fit the hamster inside the accordion?
-- modified at 22:22 Monday 19th September, 2005
|
|
|
|
|
Is your result right? Is the DecryptedText be equal to plainText?
|
|
|
|
|
Yeah, that's why I'm asking the question in the first place. The same key shouldn't be able to encrypt and decrypt the same data, no?
--Mike--
Visual C++ MVP
LINKS~! Ericahist | 1ClickPicGrabber | NEW~! CP SearchBar v3.0 | C++ Forum FAQ
Strange things are afoot at the U+004B U+20DD
|
|
|
|
|
(Posting the answer in case anyone ever sees this)
After much trial and much more error, I groked how the API works. When you call CryptExportKey(PRIVATEKEYBLOB) you actually get both keys in the blob. Also, while I was importing the public key in my code, both keys were already in my key store since I generated them on the same box, so CryptDecript() was automagically using the other key in the pair.
So calling CryptAcquireContext() with CRYPT_DELETEKEYSET removed the keys from the store; then if I import just the public key it can't encrypt then decrypt the same data. whee.
--Mike--
Visual C++ MVP
LINKS~! Ericahist | 1ClickPicGrabber | NEW~! CP SearchBar v3.0 | C++ Forum FAQ
"Linux is good. It can do no wrong. It is open source so must be right. It has penguins. I want to eat your brain."
-- Paul Watson, Linux Zombie
|
|
|
|
|
Is there a line of code that can convert an integer into a CString type?
When displaying texts, messages or reports, edit boxes has a member variable of type CString. I'd like to add a variable of integer type into the its original member variable which is CString-type. Thanks
|
|
|
|
|
It sounds like you're using MFC's DDX? If so, just make another variable that's an int - you aren't limited to one variable per control
--Mike--
Visual C++ MVP
LINKS~! Ericahist | 1ClickPicGrabber | NEW~! CP SearchBar v3.0 | C++ Forum FAQ
There is a saying in statistics that a million monkeys pounding on typewriters would eventually create a work of Shakespeare. Thanks to the Internet, we now know that this is not true.
|
|
|
|
|
If I get you right, you wan't to put an int value as a readable value in a CString, right?
In that case, you could use the CString member Format(). An example:
CString cs;
int i = 47;
cs.Format("Decimal value of i: %d, hexadecimal value of i: %04X.", i, i);
|
|
|
|
|
Hi!
When I use DeviceIoControl() to communicate with a special
device in my VC++ application,the DeviceIoControl() returns
zero,and the Getlasterror() returns 50.
I defined an IOCTL command in my driver,and used CreateFile to retrieve the device handle.
I set a breakpoint at IRP dispatch instance in my driver code with SoftICE,
but it seems that the DeviceIoControl() can not communictate with the driver.
What's the matter then?
Thanks for help!
momer
-- modified at 2:03 Tuesday 20th September, 2005
|
|
|
|
|