Thread: viahm.dll @ VIAHMGetTsens1Reg problems

  1. #1
    Registered User
    Join Date
    Oct 2006
    Posts
    4

    Lightbulb viahm.dll @ VIAHMGetTsens1Reg problems

    Code:
    #define _WIN32_WINNT   0x0500
    #define WINVER	       0x0500
    
    #include <iostream.h>
    #include <Windows.h>
    #include <stdio.h>
    
    typedef int (__stdcall *viaBOOL) (void);
    typedef int (__stdcall *viaVAL) (void);    //<---- Something is wrong here
     
    int main()
    {
    	HINSTANCE hLib;
    	hLib = LoadLibrary("viahm.dll");
    	if(hLib) {
    		viaBOOL vOpen = GetProcAddress(hLib,"VIAHMOpen");
    		if(vOpen()) {
    			viaBOOL vClose, vInit = GetProcAddress(hLib,"VIAHMInit");
    			vInit();
    			viaVAL vT1Reg = GetProcAddress(hLib,"VIAHMGetTsens1Reg");
    			vT1Reg();  //<---- And here too
    			vClose = GetProcAddress(hLib,"VIAHMClose");
    			vClose();
    		}
    	}
    	FreeLibrary(hLib);
    	return(0);
    }
    When I compile this I get no compiler errors, but get runtime error. I think this is related with bad data type viaVAR. I tryed (I think this is correct) something like this:
    Code:
    typedef void (__stdcall *viaVAL) (PDWORD);
    but after that I get compiler error: "error C2440: 'initializing' : cannot convert from 'int (__stdcall *)(void)' to 'void (__stdcall *)(unsigned long *)'"
    Thanks. Regards.

  2. #2
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465
    You can cast the return value of getprocaddress to match the function prototype of the procedure you are loading. (viaVAL) GetProcAddress(blahbluebleh);

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > typedef int (__stdcall *viaVAL) (PDWORD);
    You need to make sure it matches exactly what the real function is, in parameters and return results.

    Then you say things like
    Code:
    viaVAL vT1Reg = (viaVAL)GetProcAddress(hLib,"VIAHMGetTsens1Reg");
    DWORD param = 0;
    int result = vT1Reg( &param );
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Registered User
    Join Date
    Oct 2006
    Posts
    4
    VIAHMGetTsens1Reg isnt documented. So I dont know what parameters it takes. http://forum.ab.ru/index.php?showtop...3&#entry171973 VIAHMGetTsens1Reg : function(Val : PDWORD) : DWORD; stdcall; from here I take a guess that it return DWORD and take one unsigned long * as parameter but..... nothing is right. Dont know why.

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Why are you trying to call an undoumented function?

    Do you even know if it exists or not?

    How do you know if you need to call other things prior to calling that function?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  6. #6
    Registered User
    Join Date
    Oct 2006
    Posts
    4
    Hmz...I know ehre an error is. It is in VIAHMInit. It returns 0. Dont know why... So other program part is bad... :/
    Last edited by The_N; 10-15-2006 at 10:34 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. No clue how to make a code to solve problems!
    By ctnzn in forum C Programming
    Replies: 8
    Last Post: 10-16-2008, 02:59 AM
  2. C Pointers Problems
    By mhelal in forum C Programming
    Replies: 8
    Last Post: 01-10-2007, 06:35 AM
  3. String Manipulation problems -_-
    By Astra in forum C Programming
    Replies: 5
    Last Post: 12-13-2006, 05:48 PM
  4. contest problems on my site
    By DavidP in forum Contests Board
    Replies: 4
    Last Post: 01-10-2004, 09:19 PM
  5. DJGPP problems
    By stormswift in forum C Programming
    Replies: 2
    Last Post: 02-26-2002, 04:35 PM