473,372 Members | 901 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,372 software developers and data experts.

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 8850
Banfa
9,065 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,065 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,065 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

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

Similar topics

2
by: greyham | last post by:
Hi. I'm a beginner to C++ so bear with me. I'm trying to pass a character array to a new thread so I thought I could pass the pointer to the character array and cast it as a LPVOID (I know nothing...
3
by: George Ter-Saakov | last post by:
How do i call from managed C++ function wich accepts LPCSTR? void AddName( System::String *sName ) { AddName( (LPCSTR) sName )); -- does not compile. } George.
13
by: Joe Thompson | last post by:
Hi, I am using VS 2003 writing a managed C++ windows app. I am calling PlaySound. The first parameter is a LPCSTR. I have a String *str representing a filename. I like using the String class...
7
by: Russell Mangel | last post by:
I have been doing some C++ Interop using the new VS2005 (June Beta). I am exposing these methods to .NET clients. I ran into some WinAPI methods which use LPVOID types, and I don't understand...
6
by: John Lucas | last post by:
I wish to call an unmanaged function from vb delacred as so: #define DllExport __declspec(dllexport) DllExport int WINAPI DllAlcWrite(HANDLE, LPCSTR, int); I have tried: 1.) Private...
9
by: Hugo Amselschlag | last post by:
Hi there, I've implemented a local system hook to suppress certain windows beeing displayed by the axWebbrowser control. Now I need some more information before I can decide, whether to suppress...
5
by: Steven Hill | last post by:
Hello All! Has C# any classes to convert html page to gif or tif? Anyone could please, give how to do it? Br Wew
1
by: danmilkman | last post by:
Hi Y'all Can someone help me convert the next few lines of code from c++ to c#? I've given it a try myself but my program keeps crashing when I use my c# code. I think the difficulty lies in...
2
by: Sean F. Aitken | last post by:
Good afternoon, We have an app that uses a CMap with CString types for values and accepts LPCSTR as the parameter. The object being created is on the heap (created dynamically). A leak detector...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.