use createfile to write to ports?

trying to figure out how exactly i can write hex values (ex 0x3) to my computers lpt1 without using any 3rd party methods.

so exclusively using the winapi, what exactly is the syntax to write to lpt1?
this is what i've tried but get compile error. and if i change valuetosend to
 
char valuetosend[4]="0x3";

it just sits at the console screen.

writefile cannot convert parameter 1 from int to lpcvoid

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <windows.h>
#include <iostream>
#include <fstream>

int main()
{
HANDLE WINAPI test =CreateFileA("LPT1", GENERIC_WRITE, 0, 0, CREATE_ALWAYS, FILE_FLAG_NO_BUFFERING, 0);

int valuetosend=0x3;

WriteFile(test,valuetosend, sizeof(valuetosend), &written,0)
return 0;
}
Last edited on
Are you sure the error message says parameter 1? I'm prettry sure it sould say parameter 2 is the problem.

Check up on the WriteFile function. Parameter 2 should be a POINTER to the buffer or data to be written.

I assume in your real code you have the variable called written because I don't see it here.

WriteFile(test, &valuetosend, sizeof(valuetosend), &written,0)
Last edited on
you are correct on both of your assumptions... sorry wrote it right before i went to bed lol

but i will pass an integer pointer and see what happens. thanks for the reply.
Topic archived. No new replies allowed.