468,491 Members | 2,048 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,491 developers. It's quick & easy.

Converting LPCSTR to LPVOID

5
Hello Everyone ,
I'm trying to convert an LPCSTR to LPVOID for use in DeviceIOControl.
But when i use LPVOID test = (LPVOID)test_lpcstr then it doesn't work ,
When i use LPVOID test = "TEST" , then it works , so it must have something to do with the conversion.
Any ideas ?

Note: i'm very new to C++
Sorry for my poor english

Edit: DeviceIoControl(driverHandle, CHANGE_PREFIX, "TEST", sizeof("TEST"), szTemp, sizeof(szTemp), &dwReturn, NULL) Works , but
LPVOID var = "TEST";
DeviceIoControl(driverHandle, CHANGE_PREFIX, var, sizeof(var), szTemp, sizeof(szTemp), &dwReturn, NULL);
Doesn't.
Sep 10 '06 #1
7 8216
Banfa
9,055 Expert Mod 8TB
Please discribe what you mean by

"it doesn't work"
Sep 10 '06 #2
Toni
5
Well....it doesn't send the string to the driver...
Sep 12 '06 #3
Banfa
9,055 Expert Mod 8TB
Well....it doesn't send the string to the driver...
The problem is not the pointer but your use of the sizeof operator

sizeof("TEST") = 5 (4 characters of TEST plus the NULL terminator)

LPVOID var = "TEST";

sizeof(var) = 4 (size of a pointer)

Obviously you may expect this to work with "TEST" but not with a longer string.

You should use strlen to get the length of your input buffer string if it is actully a string.

Also why declare a LPVOID, why not just use a char * ?
Sep 12 '06 #4
Toni
5
well.... i think i did have to declare an LPVOID because of the MSDN docs...
Sep 14 '06 #5
Toni
5
Okay , i fixed it! , but it did work fine with sizeof
this was the code:
char test[256] = {"TEST"};
char szTemp[256] = {0};
DeviceIoControl(driverHandle, CHANGE_PREFIX, test, sizeof(test), szTemp, sizeof(szTemp), &dwReturn, NULL);

But now i did got another problem , i can't use this code:
LPCSTR test_str = "TEST";
char test[256] = {(char)test_str};

do you know how to do it?
Sep 14 '06 #6
Banfa
9,055 Expert Mod 8TB
Okay , i fixed it! , but it did work fine with sizeof
this was the code:
char test[256] = {"TEST"};
char szTemp[256] = {0};
DeviceIoControl(driverHandle, CHANGE_PREFIX, test, sizeof(test), szTemp, sizeof(szTemp), &dwReturn, NULL);
That is because in this code you are taking sizeof an array where originally you where taking sizeof a pointer. I have seen many people accidentally declare the wrong thing because of MS docs, articularly declaring pointers where they should be declaring objects and dereferencing them.

But now i did got another problem , i can't use this code:
LPCSTR test_str = "TEST";
char test[256] = {(char)test_str};

do you know how to do it?
You can not initialise a char array from a pointer to char just use strcpy to copy the data from the pointer to the array.

strcpy(test, test_str);
Sep 15 '06 #7
Toni
5
Thanks!
I'm now developing a driver which uses these arguments....
I can use it with DbgPrint but not with memcmp...this is the code ,
PCHAR pInputBuffer = Irp->AssociatedIrp.SystemBuffer;
if(pInputBuffer) {
if(StringNullTerminated(pInputBuffer,irpStack->Parameters.DeviceIoControl.InputBufferLength,&dwD ataRead))
{
test = (const void*)pInputBuffer;
DbgPrint(test);
}
if(0 == memcmp( process_name.Buffer, test, 4)) {
DbgPrint("It worked!");
}

Note: process_name is an ANSI_STRING , test is declared as const void *test
irpStack is a PIO_STACK_LOCATION

Hope the code and the notes helps ,
Bye!
Toni

Edit: dwDataRead is declared as UINT dwDataRead = 0 and Irp is declared as IN PIRP Irp
Sep 20 '06 #8

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by greyham | last post: by
3 posts views Thread by George Ter-Saakov | last post: by
13 posts views Thread by Joe Thompson | last post: by
6 posts views Thread by John Lucas | last post: by
9 posts views Thread by Hugo Amselschlag | last post: by
5 posts views Thread by Steven Hill | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.