|
i downloaded this code and it's in c++. it's suppose to read the cpu temperature and display the result but i can't get it to run. can someone please massage it and help me get it to run becuase i don't know c++ that well. it's suppose to get the cpu temp from a winbond W83697HF/F chip.
thanks,
Rob Tomson
//
// Simple Winbond W83697HF/F chip motherboard and cpu temp reader
// Require giveio.sys driver under winXP/2000/NT
// Used compiler: visual C++ 6
// Autor: Sander Aiaots
// E-Mail: san@ejaam.com
// I also do not take any responsibility if this program should harm your computer
//
#include <iostream.h>
#include <windows.h>
#include <conio.h>
// By the manual we have two ports to use
// 0x295 - the INDEX port and
// 0x296 - the DATA port
#define INDEX 0x295
#define DATA 0x296
#define BANK_SET 0x4e // lowest three bitti set a bank, in manual lk97 and lk109
#define CPU_TEMP 0x50 // BANK 0 0x4e = xxxxx001
#define MBM_TEMP 0x67 // 0x4e = xxxxx000
// lets give us a direct I/O access under winXP/2000/NT
// this part is not needed under win9x
int inline openIO(){
HANDLE h;
h = CreateFile("\\\\.\\giveio", GENERIC_READ, 0, NULL,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if(h == INVALID_HANDLE_VALUE) {
cout << "Couldn't access giveio device\n";
return 1;
}
CloseHandle(h);
return 0;
}
int main(){
// lets give us a direct I/O access under winXP/2000/NT
// this part is not needed under win9x
if(openIO()) return -1;
// Set Bank register to BANK0
_outp(INDEX, BANK_SET);
_outp(DATA, _inp(DATA)|0x01);
//
_outp(INDEX, CPU_TEMP);
cout << "CPU temp: " << _inp(DATA) << "C\n";
// lets unset BANK register, to get Motherboard temperature
_outp(INDEX, BANK_SET);
_outp(DATA, _inp(DATA)&0xf8);
_outp(INDEX, MBM_TEMP);
cout << "MBM temp: " << _inp(DATA) << "C\n";
return 0;
}
--
There are 10 kinds of people. Those who understand binary and those who don't.
|
|
|
|
|
If you are running Windows XP/2000/NT, you must download and install the GiveIO device driver, which this code fragment is using.
Here is a link: GiveIO Device Driver[^]
Under Windows 98/Me, this driver is not required, as each application may read or write data from any port.
If you are running Windows 95/98/Me, I suggest you comment out the lines in the main function where OpenIO method is called. Otherwise the program will always fail to open the port, and thus the main function will cease it's execution.
Remember that this particular piece of code has no security-checks applied: REMEMBER TO CHECK THE PORT DESIGNATIONS AND DATA LENGTHS ON YOUR VERY OWN MANUAL AND POSSIBLY WITH THE MANUFACTURER OF YOUR MOTHERBOARD / CPU BEFORE RUNNING THIS PROGRAM.
Otherwise, the ports the program writes to/reads from might be incorrect, and thus result in data being written to somewhere where it does not belong. Such operations may cause a system-wide failure or even damaged hardware. I suggest you consult with the maker of your motherboard to make perfectly sure that the ports specified in the file are correct. If you do not, then the risks are entirely yours.
-Antti Keskinen
----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
|
|
|
|
|
Hi!
I am writting a static library. I noticed it does not export any of the templated functions. I have been looking all over MSDN to see if there is any issue with static library and templates but nothing so far.
So the question is, is it possible to use a template function in a statically linked library?
Thanks for your answers,
Rob
|
|
|
|
|
Robert Buldoc wrote:
So the question is, is it possible to use a template function in a statically linked library?
Yes. Remember that for this to work all of the implementation of the template must be in the header file.
John
|
|
|
|
|
Well, if the template functions is implemented in the header file they are not really located in the library. The code generated by the compiler will be in the client of the library, not in the library. It cannot be any other way as the template functions are compiled when they are used. The library can't have any prior knowledge of which specializations of the template will be used.
The only way to export template functions (that I know of) is to explicit instantiate the functions in the library. See MSDN Q239436 for an explanation. However, if you explicit instatiate template member functions on VC++ 6.0 you get an internal compiler error!
br
Steen
Cheers
Steen.
"To claim that computer games influence children is ridiculous. If Pacman had influenced children born in the 80'ies we would see a lot of youngsters running around in dark rooms eating pills while listening to monotonous music"
|
|
|
|
|
Steen Krogsgaard wrote:
The only way to export template functions (that I know of) is to explicit instantiate the functions in the library.
Putting template functions in a library is the same as putting template source code in a .cpp. Unless you explicitlty instantiate it you can not use it outside of the .cpp file it is defined. That is why in most cases you must put it in the header file. See the following link:
http://www.codeproject.com/cpp/templatesourceorg.asp[^]
Steen Krogsgaard wrote:
However, if you explicit instatiate template member functions on VC++ 6.0 you get an internal compiler error!
I believe I have done this with dlls but most of the time I put all the header source code in the header file because I can not possibly explicitly instantiate all possible combinations of things I will want to use with the template.
John
|
|
|
|
|
I think we agree. I just don't see the sense of putting the template definition/implementation in a dll library if it is never being instantiated in the library. And I agree that explicit instantiations goes against the whole idea with templates.
The internal compiler error (C1001) is confirmed by MS and documented in Q179271. It happens when you have more than one explicit instantiation (which must be quite common, otherwise there is no reason to use templates in the first place )
Cheers
Steen.
"To claim that computer games influence children is ridiculous. If Pacman had influenced children born in the 80'ies we would see a lot of youngsters running around in dark rooms eating pills while listening to monotonous music"
|
|
|
|
|
Steen Krogsgaard wrote:
I just don't see the sense of putting the template definition/implementation in a dll library if it is never being instantiated in the library.
I do this because I package all my dlls with their own installer and it makes it easier to use and keep only one version of the templates if they are packaged with related classes. In general the classes of the dll may use the templates internally but for the most part they don't use them externally.
Steen Krogsgaard wrote:
The internal compiler error (C1001) is confirmed by MS and documented in Q179271.
I'll take a look at that. I find it hard to believe that I don't have more than one explicit instantiation somewhere in my dll interface code but its possible.
John
|
|
|
|
|
John M. Drescher wrote:
I'll take a look at that. I find it hard to believe that I don't have more than one explicit instantiation somewhere in my dll interface code but its possible.
It's only a problem in VC++ 5.0 and 6.0, the problem was corrected in VC++.NET (mentioned in Q179271 available online. The one I quoted was from my October 2001 MSDN CDs).
Cheers
Steen.
"To claim that computer games influence children is ridiculous. If Pacman had influenced children born in the 80'ies we would see a lot of youngsters running around in dark rooms eating pills while listening to monotonous music"
|
|
|
|
|
I have a multiple object solution. How do I call from project2 a method in
project1? I thought it is project1.method1();. Also, do I need to add
header and other stuff to project1 so that it knows how to find method1?
If there is some sample code available on line, that would be easiest.
The projects are a mixture of C#, C++, and C. I am most interested in the
C or C++ angle.
I would have search for the solution, but I have no idea what keyword to begin with. Thanks.
glam
|
|
|
|
|
I meant multiple project solution.
glam
|
|
|
|
|
> How do I call from project2 a method in project1?
In C/C++ CreateRemoteThread should do it.
> Also, do I need to add header and other stuff
> to project1 so that it knows how to find method1?
Simply pass the address of ThreadFunc from project1 to project2 via some kind of IPC (Interprocess Communication).
RK
|
|
|
|
|
I have created a DDB bitmap of size (1024x2048) and have selected it into a
compatible DC. Here is the code:
hdc = GetDC (hwnd);
hBitmap = CreateCompatibleBitmap (hdc, 1024, 2048);
hdcMem = CreateCompatibleDC (hdc);
SelectObject( hdcMem, hBitmap);
ReleaseDC (hwnd,hdc);
My problem is when I draw on the hdcMem and then bitblt it to my Window DC.
Everything works fine until I try a bitblt with an X coordinate (hdcMem)
greater than 800. My current screen Resolution is 800x600. Why is this?
How can I fix it? This is not a problem for the Y axis. I suspect that the
hdcMem has some sort of limitations based on the current resolution, but I
can't figure it out.
What happens is that the bitmap seems to be cut in half. The bitmap displays fine up to the 800 point, but after that, it doesn't show at all.
|
|
|
|
|
try on using stretchblt()
Hello World!
|
|
|
|
|
Say I know the address of a function (does this help), I want it to call my copy of the function, and then the original function.
I want to do it without making a wrapper, and without hooking GetProcAddress because I can already do it that way, but i'd like a much more direct way possibly involving inline asm etc.
Any help + ideas is appreciated.
|
|
|
|
|
> I want to do it without making a wrapper, and without hooking GetProcAddress ...
You have to modify the entry point of the original function so that it first executes a JMP instruction to your implementation.
Check this link:
http://www.fengyuan.com/article/wmprint.html[^]
There you will find a nice user32!BeginPaint hook implementation. However, because most user32 and kernel32 functions call an appropriate function in ntdll.dll, rather than executing the 0x2E interrupt directly (like BeginPaint does), your implementation will probably differ somewhat too; it will always depend on how the entry point of the original function looks like.
More useful links:
1. Intel OpCodes[^]
2. Api Hooking Revealed[^]
3. API Spying Techniques for Windows 9x, NT and 2000 [^]
Regards,
RK
|
|
|
|
|
Hi!
How can i handle the click over a system tray baloon tip?
Thanks for your answer!
|
|
|
|
|
Hi,
check out this article. Beyond your question it provides a handy class to use message balloons in the system tray.
Peter Molnar
|
|
|
|
|
|
|
I am trying to create my first a multi-threaded dev-studio library project.
Is there a way to register a thread "cleanup" function that gets called each time a thread exits?
Here are some constraints for any suggestions you provide me:
1) I think I want my library statically linked. I see that for DLLs, DllMain() gets called each time a thread "detaches". This might be an appropriate place for me to stick my clean-up code if I were writing a DLL, but I don't think I want a DLL.
2) I don't want users of my library to have to write any code to get the cleanup function called. It should all be completely hidden.
3) I really only need my cleanup function executed for exiting threads that previously used particular functions from my library. So I do have a place to register the thread-exit function if there is a way to do that at all.
Thanks much for your help.
Matt Busche
|
|
|
|
|
> Is there a way to register a thread "cleanup" function
> that gets called each time a thread exits?
Hm..the first solution that comes to my mind: Call GetExitCodeThread periodically.
DWORD dwExitCode;
GetExitCodeThread( hThread, &dwExitCode);
if( dwExitCode == STILL_ACTIVE )
else
Anyway, why don't you simply call the cleanup routine at the end of ThreadFunc (just before calling return )?
DWORD WINAPI ThreadFunc( LPVOID lpParameter )
{
MyCleanUpRoutine();
return 0;
} Regards,
RK
|
|
|
|
|
Robert,
I guess I'm not a big fan of polling. As for your second suggestion: I'm trying to write a library that other developers will use. My library won't be spawning threads -- the application written by someone else will. So to pursue your suggestion, I'd have to include in my library notes, "oh, and be sure to call MyCleanUpRoutine() before your thread exits. Don't really care for that either. I guess I'm going to have to figure out how to get a DLL to work for me instead.
Actually, I think a DLL will work for me, but my initial attempts to create a DLL have not gone so well -- having problems getting global data from the DLL to link.
Thanks much for your response.
Matt Busche
|
|
|
|
|
A *.dll would perfectly suit your needs. What you have to do is:
1.Create a *.dll and export all the functions you want your users to call
2.Make sure that the global data (if any) that simultanious threads can access (i.e. if two or more users at a time call the same function) is protected with syncronization objects like Critical sections
3.If your user calls LoadLibrary, your DllMain gets called with DLL_PROCESS_ATTACH, do some initialization, maybe keep reference count of attached clients, when your user calls FreeLibrary your DllMain gets called with reason DLL_PROCESS_DETACH. This is the place to call your CleanUpFunction()
Summary: your user has only to call LoadLibrary on your *.dll, GetProcAddress on the function, and FreeLibrary to get detached from your lib.
Peter Molnar
|
|
|
|
|
Peter,
Thanks for your reply. I actually started to do this and only just now discovered that this only works for RUN-TIME dynamic-linking of a DLL. (I.e., where you use the LoadLibrary call just like you said.) I saw some sample code on how to use LoadLibrary and GetProcAddress to call a single simple function from a DLL, but I'm not exporting a single simple function, I'm exporting a handfull of C++ concrete and abstract classes (along with all their numerous member methods and overloaded operators). It is not clear to me how you'd use run-time linking for such a library. Supppose Peter, you inherited from one of my abstract base-classes, then when you wrote your constructor, how would you call my base class constructor that is exported from my DLL?
And even if it's possible, my whole objective is to make my software as easy as possible to use. I certainly wouldn't want my users to have to jump through any flaming hoops to call a base class constructor or call the "=" operator for a class.
Here's a thought. What if I had two libraries? Library ALPHA has all my user visible software and could be built arbitrarily for either dynamic or static linkage. If built as a DLL it would be expected to be used with load-time dynamic-linkage. DLL BETA has nothing in it but a DllMain. Now, here's the trick: suppose DLL ALPHA secretly does a LoadLibrary call on BETA via some singleton constructor found in ALPHA. This singleton is instantiated the first time a user of ALHPA references resources that require thread initialization and cleanup activities. Then, I would presume that every subsequent thread spawn and delete would cause this DllMain in BETA to be invoked, would it not? I presume also that DllMain in BETA could invoke methods defined in ALPHA (to effect thread initialization and cleanup.)
I'm going to investigate this idea further and maybe try it out.
Let me know if I misunderstood the implications of your email. I've been battling this silly problem for a week now. If I don't come up with a better solution soon, I'll have to simply publish a threadCleanup method that must be called by users of my library on thread exit, but I really don't want to have to do this.
Once again, thanks sincerely for your help.
Matt
|
|
|
|