Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

inpout.dll and Visual C++

Status
Not open for further replies.
Styx said:
IT is very bad practice to start putting DLL's into the system32 folder that did not come with the OS.

No, it's bad practice to start putting DLLs into the system32 folder that *did* come with the OS.

It was that kind of practice that has lead to DLL-hell

No. What lead to DLL hell are stupid installation programs and the lack of control on Windows' part.


DLL-Hell: When a programmer customises a system-dll and puts that in the system folder. Another programmer customises the same dll (for another program) as a result program1 no longer works

That's just bad programming practice. If the second programmer implements the original DLL interface correctly, both programs will work. If the second programmer isn't confident his modifications will not break other programs, then yes, he should keep his version of the DLL on a separate, "private" folder.

Leave the DLL in the working directory to ensure no pain later

Leaving that DLL in the working directory or putting in the system32/windows folder doesn't change much on the programmer's machine. What you decribed as DLL-Hell though, every programmer should keep in mind when *distributing* a software project.

In fact, I'd find it easier to have the DLL out of my way into the win/sys32 folder during development, but to each his own I guess...
 
i will make this as easy as possible without being horrible.
1)copy the files out of the zip to the debug folder where the final built .EXE will be.
2)inport the dll and lib to the project, use the code shown.
3)use the built .EXE and inpout.DLL together.
 

Attachments

  • step1.jpg
    step1.jpg
    39 KB · Views: 949
  • what_should_look_like.jpg
    what_should_look_like.jpg
    28.1 KB · Views: 931
Joel Rainville said:
No. What lead to DLL hell are stupid installation programs and the lack of control on Windows' part.

Yet this entire thread is about how to bypass Windows 'control' and access the hardware 'directly', which isn't really a good thing to do under Windows.

Admittedly, by using drivers to do this, it's done in a Windows safe way, but it's still bypassing a Windows safety feature.
 
I've run this program
Code:
include "stdafx.h"
#include "conio.h"
#include "stdio.h"
#include "string.h"
#include "stdlib.h"

int main(int argc, char* argv[])
{
	short data;

	if(argc<2)
	{
		printf("Usage\n\n");
		printf("partest1.exe ,,\n\n\n");
		return 0;
	}
	
	if(!strcmp(argv[1],"read"))
	{
		data = _inp(atoi(argv[2])); 
		printf("Data read from parallel port is  ");
		printf("%d\n\n\n\n",data);
	}
	
	if(!strcmp(argv[1],"write"))
	{
		_outp(atoi(argv[2]),atoi(argv[3])); 
		printf("Data written to parallel port is  ");
		printf("%s\n\n\n\n\n",argv[3]);
	}
	return 0;
}

I did just what danielsmusic instructed,the program was built successfully (i think), and it opened a window, i attached the image of the window below, but as I pressed a key, the window disappeared afterwards, I haven't done the hardware yet, but do you think that it worked?
but when I replaced the _outp(atoi(argv[2]),atoi(argv[3])) by Out32(atoi(argv[2]),atoi(argv[3])), this was the error that occurred:
error C2065: 'Out32' : undeclared identifier
I think I saw someone posted in here that I need to replace _outp() with Out32() if I was to used the inpout32.dll?
 

Attachments

  • successful.gif
    successful.gif
    8.4 KB · Views: 937
gastonanthony said:
I've run this program
Code:
include "stdafx.h"
#include "conio.h"
#include "stdio.h"
#include "string.h"
#include "stdlib.h"

int main(int argc, char* argv[])
{
	short data;

	if(argc<2)
	{
		printf("Usage\n\n");
		printf("partest1.exe ,,\n\n\n");
		return 0;
	}
	
	if(!strcmp(argv[1],"read"))
	{
		data = _inp(atoi(argv[2])); 
		printf("Data read from parallel port is  ");
		printf("%d\n\n\n\n",data);
	}
	
	if(!strcmp(argv[1],"write"))
	{
		_outp(atoi(argv[2]),atoi(argv[3])); 
		printf("Data written to parallel port is  ");
		printf("%s\n\n\n\n\n",argv[3]);
	}
	return 0;
}

I did just what danielsmusic instructed,the program was built successfully (i think), and it opened a window, i attached the image of the window below, but as I pressed a key, the window disappeared afterwards, I haven't done the hardware yet, but do you think that it worked?
but when I replaced the _outp(atoi(argv[2]),atoi(argv[3])) by Out32(atoi(argv[2]),atoi(argv[3])), this was the error that occurred:
error C2065: 'Out32' : undeclared identifier
I think I saw someone posted in here that I need to replace _outp() with Out32() if I was to used the inpout32.dll?

You don't know what the code does?

Looking at it, it's waiting for at least 2 command line arguments, the first being either commands "read" or "write", the second I'm not sure. Where did you get that source code?

error C2065: 'Out32' : undeclared identifier means there is no such thing as function 'Out32'... You sure it takes a capital 'O'?
 
Ok, sorry, just went back and read the whole thread :oops:

The instructions danielsmusic gave you are incomplete. What he describes merely copies the files to your project folders. The .lib needs to be linked to your program. In Visual Studio/C++, once your project is opened, goto Project->Settings and click the Link tab. At the very end of the Object/library modules: text input box, type the name of your library file "inpout32.lib". Rebuild the project.

From **broken link removed** :

The DLL Inpout32

The functions in the DLL are implemented in two source files, "inpout32drv.cpp" and "osversion.cpp". osversion.cpp checks the version of operating system. "inpout32drv.cpp" does installing the kernel mode driver, loading it , writing/ reading parallel port etc... The two functions exported from inpout32.dll are

1) 'Inp32', reads data from a specified parallel port register.

2) 'Out32', writes data to specified parallel port register.

So your function calls should actually read Out32 and Inp32.

Also, since you don't appear to have a header file with that DLL, you also need to add thsee definitions at the top of your source file (preferably under the #includes) :

Code:
/* ----Prototypes of Inp and Outp--- */

short _stdcall Inp32(short PortAddress);
void _stdcall Out32(short PortAddress, short data);

This will get rid of the error you got at compile time.
 
dlls stand for Dynamically Linked Libraries.
Library - Shared functions
Dynamically-Linked - Loaded only at runtime. This reduces program file sizes, memory required, and allows programs to "share" a common library. Any changes required need to be made only to the library, instead of updating all programs using the library.
 
danielsmusic said:
well if you don't want to get it right don't follow what i did!

The way you include the 2 files in your project will only copy the files to the project folder. While that's far from a bad idea, it won't do anything good unless you link the .lib to the target executable. This is a basic compiler/linker concept.

Might I suggest you read on Visual C++'s build options and project settings to get a better understanding? You could also just take a look at example programs that come with the inpout32.dll from the website gastonanthony linked in a previous post : **broken link removed**.
 
I'm not sure how to do it under windows BUT if I have a program like this

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main(void)
{
printf("%f",sin(0.8))
return 0
}



now if I compile this with

gcc test.c it will fail since I have not linked the maths libary (in Linux this is libmath.so)

So I need to do

gcc test.c -lmath

to link the maths libary (linux equiv of a DLL) into this program

YOu are going to have to do the same in windows...
 
Styx said:
I'm not sure how to do it under windows BUT if I have a program like this

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main(void)
{
printf("%f",sin(0.8))
return 0
}



now if I compile this with

gcc test.c it will fail since I have not linked the maths libary (in Linux this is libmath.so)

So I need to do

gcc test.c -lmath

to link the maths libary (linux equiv of a DLL) into this program

YOu are going to have to do the same in windows...

Exactly. Like I said, basic compiler/linker concept.
 
ok, so I tried a much simpler code, a blinking led code, it compiled, built and linked successfully, but nothing happened to my circuit. What could be wrong? I already extracted the inpout32.dll in the lib folder of VC++, in the system32 and system folder of C:\, but it still doesn't work. below are the attachments of what I did
 

Attachments

  • 2_819.gif
    2_819.gif
    17.4 KB · Views: 716
  • 3_733.jpg
    3_733.jpg
    15.1 KB · Views: 703
  • 1_264.gif
    1_264.gif
    18.9 KB · Views: 754
Good, you're almost there :)

Now, you need to send a bit more data if you want to see something happen. Try something like that :

Code:
int i, j;
for( i = 0; i < 10; i++ )
{
	for( j = 0; j < 2500; j++ )
	{
		Out32(...); // Send '1'
	}
	for( j = 0; j < 2500; j++ )
	{
		Out32(...); // Send '0'
	}
}

If everything's fine, you should see your LED blink 10 times before your program quits.
 
hahahahaha :lol: :lol: :lol:
thanks a lot to all of you guys especially to you Joel Rainville, I used the for loop that you made, i just saw one blink at first, then I changed the number of loops of 1s and 0s to 10000, and it worked perfectly!!! :D :lol: :D :lol:
just a question, do you guys know the equivalent microsecond or nanosecond of the execution of a line of instruction in visual C++?I may be needing it for servomotor control to be able to continue my robotic project
 
gastonanthony said:
just a question, do you guys know the equivalent microsecond or nanosecond of the execution of a line of instruction in visual C++?I may be needing it for servomotor control to be able to continue my robotic project

I don't think there is one?, and the mS timing isn't particularly accurate either under Windows - unless you take over the OS priorities. You should also be aware that port access is relatively slow, if you look at the links posted earlier about how port access occurs under Win32 you'll see why!.

If you want to feed servos, use a PIC to feed them, and control them via the RS232 port - PIC systems for this are commonly available.
 
gastonanthony said:
hahahahaha :lol: :lol: :lol:
thanks a lot to all of you guys especially to you Joel Rainville, I used the for loop that you made, i just saw one blink at first, then I changed the number of loops of 1s and 0s to 10000, and it worked perfectly!!! :D :lol: :D :lol:
just a question, do you guys know the equivalent microsecond or nanosecond of the execution of a line of instruction in visual C++?I may be needing it for servomotor control to be able to continue my robotic project

Well, C++ is a powerful language, simply add delay codes to it and you will get wat you want. Most probably the speed is determine by your processing power from your cpu. It should be able to handle microsecond with just a PIII.
 
ym2k said:
gastonanthony said:
hahahahaha :lol: :lol: :lol:
thanks a lot to all of you guys especially to you Joel Rainville, I used the for loop that you made, i just saw one blink at first, then I changed the number of loops of 1s and 0s to 10000, and it worked perfectly!!! :D :lol: :D :lol:
just a question, do you guys know the equivalent microsecond or nanosecond of the execution of a line of instruction in visual C++?I may be needing it for servomotor control to be able to continue my robotic project

Well, C++ is a powerful language, simply add delay codes to it and you will get wat you want. Most probably the speed is determine by your processing power from your cpu. It should be able to handle microsecond with just a PIII.

But it won't be reliable at all, and it has nothing to do with the language. Nigel's post just before yours gives a good reason why...
 
about blinking

Can some one tell me how to make my LED to blink 2,4,5, or more times...I tried how you had write but it just blink one time and thats all....Please ..
 
Hi friends the orginal questionPosted by gastonanthony is also my question,I've read alot on different forums but I can not get clear view,the problem I want toaddress is interfacing a switching module using VC++ in Win XP platform
 
to unlock the parallel port many people suggested me to use inpout.dll. I've downloaded it but how can I use it.can I include in my applications source code or in c:\ at the drivers.It is a little bit difficult for me.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top