473,408 Members | 2,832 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Want some C for today?

Hi,

I haven't written C program for years, I have this C program I need to
implement into our VB.NET application. The C program is released by the PC
manufacturer along with the system driver and DLL, but of course it doesn't
have a VB.NET version. The DLL provides function to read the CPU and System
Temperatures. At the bottom is my attempt in VB.NET, but I am getting zeros
from these functions. Any idea what I am doing wrong? What is the
equivalent of "GetProcAddress" in VB.NET?

Thanks!!!

******************** Here is the header file hwmsioapp.h
#if !defined(__HWMSIOAPP_H__)
#define __HWMSIOAPP_H__

typedef enum typevol{
_VCORE = 1,
_V5,
_V12,
_V25,
_V33
}TYPEVOL;

#endif

******************** Here is the header file hwmsioapp.c
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include "hwmsioapp.h"

// declare the following variable for interface to DLL
HMODULE hModule;

typedef int (__cdecl *HWM_READ_FAN1) (void* outptr);
typedef int (__cdecl *HWM_READ_CPUTEMP) (void* outptr);
typedef int (__cdecl *HWM_READ_SYSTEMP) (void* outptr);
typedef int (__cdecl *HWM_READ_VOLTAGE) (int type, void* outptr);

static HWM_READ_FAN1 hwm_read_cpufan1 = NULL;
static HWM_READ_CPUTEMP hwm_read_cputemp = NULL;
static HWM_READ_SYSTEMP hwm_read_systemp = NULL;
static HWM_READ_VOLTAGE hwm_read_voltage = NULL;
// end of declaraton

void print_usage(void)
{
printf("Usage: wdtapp <time-out type> <time-out value> <loop>\n\n"
" <time-out type> 0 = in minutes\n"
" 1 = in seconds\n\n"
" <time-out value> = any integer between 0 and 255\n"
" <loop> = any integer specifying times to reset WDT \n\n");
}

int __cdecl main(int argc, char ** argv)
{
int fan1, cput, syst;
float volcore, vol5, vol12, vol25, vol33;
UCHAR c;

// Load DLL library and retrieve export function
hModule = LoadLibrary("hwmsiodll.dll");
hwm_read_cpufan1 = (HWM_READ_FAN1) GetProcAddress(hModule,
"hwm_read_cpufan1");
hwm_read_cputemp = ( HWM_READ_CPUTEMP) GetProcAddress(hModule,
"hwm_read_cputemp");
hwm_read_systemp = ( HWM_READ_SYSTEMP) GetProcAddress(hModule,
"hwm_read_systemp");
hwm_read_voltage = (HWM_READ_VOLTAGE) GetProcAddress(hModule,
"hwm_read_voltage");
// end of retrieve export function

if (hwm_read_cpufan1 == 0 || hwm_read_cputemp ==0
|| hwm_read_systemp ==0 || hwm_read_voltage ==0 )
{
fprintf(stderr, "Fail to get DLL service");
FreeLibrary(hModule);
return 0;
}

fprintf(stderr, "SYSTEM HARDWARE MONITOR VALUE -\n");

c = hwm_read_cpufan1(&fan1);
//fprintf(stderr, "byte read from cpu fan1 0x%x\n", c);
fprintf(stderr, "CPUFan1 %d[RPM]\n", fan1);

c = hwm_read_cputemp(&cput);
//fprintf(stderr, "byte read from cpu temp 0x%x\n", c);
fprintf(stderr, "CPUTEMP %d[oC]\n", cput);

c = hwm_read_systemp(&syst);
//printf(stderr, "byte read from sys temp 0x%x\n", c);
fprintf(stderr, "SystemTEMP %d[oC]\n", syst);

c= hwm_read_voltage(_VCORE, &volcore);
//fprintf(stderr, "byte read from VCORE 0x%x\n", c);
fprintf(stderr, "VCORE %1.2f[vol]\n", volcore);

c= hwm_read_voltage(_V5, &vol5);
//fprintf(stderr, "byte read from V5 0x%x\n", c);
fprintf(stderr, "VOL5 %1.2f[vol]\n", vol5);

c= hwm_read_voltage(_V12, &vol12);
//fprintf(stderr, "byte read from V12 0x%x\n", c);
fprintf(stderr, "VOL12 %1.2f[vol]\n", vol12);
c= hwm_read_voltage(_V25, &vol25);
//fprintf(stderr, "byte read from V2.5 0x%x\n", c);
fprintf(stderr, "VOL2.5 %1.2f[vol]\n", vol25);

c= hwm_read_voltage(_V33, &vol33);
//fprintf(stderr, "byte read from V3.3 0x%x\n", c);
fprintf(stderr, "VOL3.3 %1.2f[vol]\n", vol33);

FreeLibrary(hModule);

return 1;
}

******************** Here is my attempt in VB.NET
Declare Function hwm_read_cpufan1 Lib "hwmsiodll.dll" (ByRef temp As
Integer) As Integer

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Dim temp As Integer, c As Integer

c = hwm_read_cpufan1(temp)

MsgBox("c=" & c & ",temp=" & temp)

End Sub


Nov 21 '05 #1
1 1241
Is the dll in the GAC or have you added a reference in vb.net?

"anthony" <an*******@controlengineer.com> wrote in message
news:ec**************@TK2MSFTNGP10.phx.gbl...
Hi,

I haven't written C program for years, I have this C program I need to
implement into our VB.NET application. The C program is released by the
PC
manufacturer along with the system driver and DLL, but of course it
doesn't
have a VB.NET version. The DLL provides function to read the CPU and
System
Temperatures. At the bottom is my attempt in VB.NET, but I am getting
zeros
from these functions. Any idea what I am doing wrong? What is the
equivalent of "GetProcAddress" in VB.NET?

Thanks!!!

******************** Here is the header file hwmsioapp.h
#if !defined(__HWMSIOAPP_H__)
#define __HWMSIOAPP_H__

typedef enum typevol{
_VCORE = 1,
_V5,
_V12,
_V25,
_V33
}TYPEVOL;

#endif

******************** Here is the header file hwmsioapp.c
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include "hwmsioapp.h"

// declare the following variable for interface to DLL
HMODULE hModule;

typedef int (__cdecl *HWM_READ_FAN1) (void* outptr);
typedef int (__cdecl *HWM_READ_CPUTEMP) (void* outptr);
typedef int (__cdecl *HWM_READ_SYSTEMP) (void* outptr);
typedef int (__cdecl *HWM_READ_VOLTAGE) (int type, void* outptr);

static HWM_READ_FAN1 hwm_read_cpufan1 = NULL;
static HWM_READ_CPUTEMP hwm_read_cputemp = NULL;
static HWM_READ_SYSTEMP hwm_read_systemp = NULL;
static HWM_READ_VOLTAGE hwm_read_voltage = NULL;
// end of declaraton

void print_usage(void)
{
printf("Usage: wdtapp <time-out type> <time-out value> <loop>\n\n"
" <time-out type> 0 = in minutes\n"
" 1 = in seconds\n\n"
" <time-out value> = any integer between 0 and 255\n"
" <loop> = any integer specifying times to reset WDT \n\n");
}

int __cdecl main(int argc, char ** argv)
{
int fan1, cput, syst;
float volcore, vol5, vol12, vol25, vol33;
UCHAR c;

// Load DLL library and retrieve export function
hModule = LoadLibrary("hwmsiodll.dll");
hwm_read_cpufan1 = (HWM_READ_FAN1) GetProcAddress(hModule,
"hwm_read_cpufan1");
hwm_read_cputemp = ( HWM_READ_CPUTEMP) GetProcAddress(hModule,
"hwm_read_cputemp");
hwm_read_systemp = ( HWM_READ_SYSTEMP) GetProcAddress(hModule,
"hwm_read_systemp");
hwm_read_voltage = (HWM_READ_VOLTAGE) GetProcAddress(hModule,
"hwm_read_voltage");
// end of retrieve export function

if (hwm_read_cpufan1 == 0 || hwm_read_cputemp ==0
|| hwm_read_systemp ==0 || hwm_read_voltage ==0 )
{
fprintf(stderr, "Fail to get DLL service");
FreeLibrary(hModule);
return 0;
}

fprintf(stderr, "SYSTEM HARDWARE MONITOR VALUE -\n");

c = hwm_read_cpufan1(&fan1);
//fprintf(stderr, "byte read from cpu fan1 0x%x\n", c);
fprintf(stderr, "CPUFan1 %d[RPM]\n", fan1);

c = hwm_read_cputemp(&cput);
//fprintf(stderr, "byte read from cpu temp 0x%x\n", c);
fprintf(stderr, "CPUTEMP %d[oC]\n", cput);

c = hwm_read_systemp(&syst);
//printf(stderr, "byte read from sys temp 0x%x\n", c);
fprintf(stderr, "SystemTEMP %d[oC]\n", syst);

c= hwm_read_voltage(_VCORE, &volcore);
//fprintf(stderr, "byte read from VCORE 0x%x\n", c);
fprintf(stderr, "VCORE %1.2f[vol]\n", volcore);

c= hwm_read_voltage(_V5, &vol5);
//fprintf(stderr, "byte read from V5 0x%x\n", c);
fprintf(stderr, "VOL5 %1.2f[vol]\n", vol5);

c= hwm_read_voltage(_V12, &vol12);
//fprintf(stderr, "byte read from V12 0x%x\n", c);
fprintf(stderr, "VOL12 %1.2f[vol]\n", vol12);
c= hwm_read_voltage(_V25, &vol25);
//fprintf(stderr, "byte read from V2.5 0x%x\n", c);
fprintf(stderr, "VOL2.5 %1.2f[vol]\n", vol25);

c= hwm_read_voltage(_V33, &vol33);
//fprintf(stderr, "byte read from V3.3 0x%x\n", c);
fprintf(stderr, "VOL3.3 %1.2f[vol]\n", vol33);

FreeLibrary(hModule);

return 1;
}

******************** Here is my attempt in VB.NET
Declare Function hwm_read_cpufan1 Lib "hwmsiodll.dll" (ByRef temp As
Integer) As Integer

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Dim temp As Integer, c As Integer

c = hwm_read_cpufan1(temp)

MsgBox("c=" & c & ",temp=" & temp)

End Sub

Nov 21 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Chris Cioffi | last post by:
I started writing this list because I wanted to have definite points to base a comparison on and as the starting point of writing something myself. After looking around, I think it would be a...
7
by: Vinnie Davidson | last post by:
Hello! I'm trying to get all records from my SQL Server Database with "DeadlineDate" = today (not today - 24 hours). All records has a field called "DeadlineDate", and the date is stored in...
1
by: s.shahzaib.ali | last post by:
I want to make analog clock skin of windows media player so how can i roteate the layer upto 360 degrees with the help of javascript please tell me iam very anxious about it. iam the first and only...
182
by: Jim Hubbard | last post by:
http://www.eweek.com/article2/0,1759,1774642,00.asp
2
by: tshad | last post by:
I am trying to check the date of my field to check if it is greater that today, but I am getting an error. I am using : <asp:CompareValidator runat="server"...
4
by: Chris | last post by:
Hello, I am attempting to build a MS SQL query that will return data from "today"; today being current day 8:00AM-10:00PM today. My goal is to return the data from a table that is written to...
1
by: dmbkiwi | last post by:
I'm using the dateutil module from http://labix.org/python-dateutil. Am I right in thinking that the rrules module doesn't acknowledge days before today? An example of the issue: >>>...
5
by: M Skabialka | last post by:
I am creating my first Visual Studio project, an inventory database. I have created a form and used written directions to add data from a table to the form using table adapters, data sets, etc. ...
1
by: cinsky | last post by:
Hi, I got confused when I learned the function datetime.today(). So far I learned, unless an instance is created, it is not possible to call the class method. For example: class Foo: def...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.