Want some C for today?

A

anthony

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
 
S

Shawn

Is the dll in the GAC or have you added a reference in vb.net?

anthony said:
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
 
Top