so nachdem ich mich dumm und fast Dä(h)mlich gesicht habe hier ein funktionierendes DevC++ skript das den LPT Controlregister (ausgabe) setzen kann unter winXP und unter Vista PS: test_read_control und system("pause") ist in der Main ausgeklammert und sollte zuerst getestet werden die dll muss natürlich im suchpfad sein !!!
1 | #include <stdio.h> |
2 | #include <stdlib.h> |
3 | #include <conio.h> |
4 | #include <windows.h> |
5 | /* Definitions in the build of inpout32.dll are: */
|
6 | /* short _stdcall Inp32(short PortAddress); */
|
7 | /* void _stdcall Out32(short PortAddress, short data); */
|
8 | /* prototype (function typedef) for DLL function Inp32: */
|
9 | typedef short (_stdcall *inpfuncPtr)(short portaddr); |
10 | typedef void (_stdcall *oupfuncPtr)(short portaddr, short datum); |
11 | #define PPORT_BASE 0x378
|
12 | void test_write(void); |
13 | void test_read_control(void); |
14 | /* After successful initialization, these 2 variables
|
15 | will contain function pointers.
|
16 | */
|
17 | inpfuncPtr inp32fp; |
18 | oupfuncPtr oup32fp; |
19 | /* Wrapper functions for the function pointers
|
20 | - call these functions to perform I/O.
|
21 | */
|
22 | short Inp32 (short portaddr) |
23 | {
|
24 | return (inp32fp)(portaddr); |
25 | }
|
26 | |
27 | void Out32 (short portaddr, short datum) |
28 | {
|
29 | (oup32fp)(portaddr,datum); |
30 | }
|
31 | |
32 | |
33 | int main(void) |
34 | {
|
35 | HINSTANCE hLib; |
36 | |
37 | short x; |
38 | int i; |
39 | |
40 | |
41 | /* Load the library */
|
42 | hLib = LoadLibrary("inpout32.dll"); |
43 | |
44 | if (hLib == NULL) { |
45 | fprintf(stderr,"LoadLibrary Failed.\n"); |
46 | return -1; |
47 | }
|
48 | |
49 | /* get the address of the function */
|
50 | |
51 | inp32fp = (inpfuncPtr) GetProcAddress(hLib, "Inp32"); |
52 | |
53 | if (inp32fp == NULL) { |
54 | fprintf(stderr,"GetProcAddress for Inp32 Failed.\n"); |
55 | return -1; |
56 | }
|
57 | |
58 | |
59 | oup32fp = (oupfuncPtr) GetProcAddress(hLib, "Out32"); |
60 | |
61 | if (oup32fp == NULL) { |
62 | fprintf(stderr,"GetProcAddress for Oup32 Failed.\n"); |
63 | return -1; |
64 | }
|
65 | |
66 | |
67 | /*******************************************************/
|
68 | /** IF WE REACHED HERE, INITIALIZED SUCCESSFUL ******/
|
69 | /*******************************************************/
|
70 | //test_read_control();
|
71 | test_write(); |
72 | //test_read_control();
|
73 | /* finished - unload library and exit */
|
74 | FreeLibrary(hLib); |
75 | //system("pause");
|
76 | return 0; |
77 | }
|
78 | |
79 | // TEST: Write constant to Control register)
|
80 | void test_write(void) { |
81 | short x; |
82 | int i; |
83 | Out32(0x37A,0xCA); // Set Output-only again |
84 | }
|
85 | // TEST: READ data from control
|
86 | void test_read_control(void) { |
87 | short x; |
88 | int i; |
89 | i=0x37A; |
90 | x = 12; |
91 | x = Inp32(i); |
92 | printf("Port read (%04X)= %04X\n",i,x); |
93 | }
|