15,898,222 members
Sign in
Sign in
Email
Password
Forgot your password?
Sign in with
home
articles
Browse Topics
>
Latest Articles
Top Articles
Posting/Update Guidelines
Article Help Forum
Submit an article or tip
Import GitHub Project
Import your Blog
quick answers
Q&A
Ask a Question
View Unanswered Questions
View All Questions
View C# questions
View C++ questions
View Javascript questions
View Visual Basic questions
View Python questions
discussions
forums
CodeProject.AI Server
All Message Boards...
Application Lifecycle
>
Running a Business
Sales / Marketing
Collaboration / Beta Testing
Work Issues
Design and Architecture
Artificial Intelligence
ASP.NET
JavaScript
Internet of Things
C / C++ / MFC
>
ATL / WTL / STL
Managed C++/CLI
C#
Free Tools
Objective-C and Swift
Database
Hardware & Devices
>
System Admin
Hosting and Servers
Java
Linux Programming
Python
.NET (Core and Framework)
Android
iOS
Mobile
WPF
Visual Basic
Web Development
Site Bugs / Suggestions
Spam and Abuse Watch
features
features
Competitions
News
The Insider Newsletter
The Daily Build Newsletter
Newsletter archive
Surveys
CodeProject Stuff
community
lounge
Who's Who
Most Valuable Professionals
The Lounge
The CodeProject Blog
Where I Am: Member Photos
The Insider News
The Weird & The Wonderful
help
?
What is 'CodeProject'?
General FAQ
Ask a Question
Bugs and Suggestions
Article Help Forum
About Us
Search within:
Articles
Quick Answers
Messages
Comments by Member 9063138 (Top 2 by date)
Member 9063138
8-Jun-12 8:45am
View
HI....
I TRY THE FOLLOWING CODE!!!!:
#include <stdio.h>
#include <conio.h>
#include <windows.h>
/* Definitions in the build of inpout32.dll are: */
/* short _stdcall Inp32(short PortAddress); */
/* void _stdcall Out32(short PortAddress, short data); */
/* prototype (function typedef) for DLL function Inp32: */
typedef short (_stdcall *inpfuncPtr)(short portaddr);
typedef void (_stdcall *oupfuncPtr)(short portaddr, short datum);
#define PPORT_BASE 0x378
// Prototypes for Test functions
void test_read8(void);
void test_write(void);
void test_write_datum(short datum);
/* After successful initialization, these 2 variables
will contain function pointers.
*/
inpfuncPtr inp32fp;
oupfuncPtr oup32fp;
/* Wrapper functions for the function pointers
- call these functions to perform I/O.
*/
short Inp32 (short portaddr)
{
return (inp32fp)(portaddr);
}
void Out32 (short portaddr, short datum)
{
(oup32fp)(portaddr,datum);
}
int main(void)
{
HINSTANCE hLib;
short x;
int i;
/* Load the library */
hLib = LoadLibrary("inpout32.dll");
if (hLib == NULL) {
fprintf(stderr,"LoadLibrary Failed.\n");
return -1;
}
/* get the address of the function */
inp32fp = (inpfuncPtr) GetProcAddress(hLib, "Inp32");
if (inp32fp == NULL) {
fprintf(stderr,"GetProcAddress for Inp32 Failed.\n");
return -1;
}
oup32fp = (oupfuncPtr) GetProcAddress(hLib, "Out32");
if (oup32fp == NULL) {
fprintf(stderr,"GetProcAddress for Oup32 Failed.\n");
return -1;
}
/*******************************************************/
/** IF WE REACHED HERE, INITIALIZED SUCCESSFUL ******/
/*******************************************************/
/* now test the functions */
/***** Read 8 bytes at I/O base address */
test_read8();
/***** Write 0x75 to data register and verify */
test_write();
/***** One more time, different value */
test_write_datum(0xAA);
/* finished - unload library and exit */
FreeLibrary(hLib);
return 0;
}
/*
TEST: Read inputs of 8 registers from PORT_BASE address
*/
void test_read8(void) {
short x;
int i;
/* Try to read 0x378..0x37F, LPT1: */
for (i=PPORT_BASE; (i<(PPORT_BASE+8)); i++) {
x = Inp32(i);
printf("Port read (%04X)= %04X\n",i,x);
}
}
/*
TEST: Write constant 0x77 to PORT_BASE (Data register)
*/
void test_write(void) {
short x;
int i;
/***** Write the data register */
i=PPORT_BASE;
x=0x75;
/***** Write the data register */
Out32(i,x);
printf("Port write to 0x%X, datum=0x%2X\n" ,i ,x);
/***** And read back to verify */
x = Inp32(i);
printf("Port read (%04X)= %04X\n",i,x);
/***** Set all bits high */
x=0xFF;
Out32(i,x);
/***** Now, set bi-directional and read again */
Out32(PPORT_BASE+2,0x20); // Activate bi-directional
x = Inp32(i);
printf("Set Input, read (%04X)= %04X\n",i,x);
Out32(PPORT_BASE+2,0x00); // Set Output-only again
x = Inp32(i);
printf("Reset Ouput, read (%04X)= %04X\n",i,x);
}
/*
TEST: Write data from parameter
*/
void test_write_datum(short datum) {
short x;
int i;
i=PPORT_BASE;
x = datum;
/***** Write the data register */
Out32(i,x);
printf("Port write to 0x%X, datum=0x%2X\n" ,i ,x);
/***** And read back to verify */
x = Inp32(i);
printf("Port read (%04X)= %04X\n",i,x);
}
BUT ERREOR HAPPEND:
error C2664: 'LoadLibraryW' : cannot convert parameter 1 from 'const char [13]' to 'LPCWSTR'
WHY????????????
Member 9063138
3-Jun-12 7:08am
View
SORRY LINK IS NOT OPEN?? WHY