Problem with linking a .dll file

This is a discussion on Problem with linking a .dll file within the C++ Programming forums, part of the General Programming Boards category; Hi there . I've got a problem getting a program to work. I'm quite a newbie so please explain things ...

  1. #1
    Registered User
    Join Date
    Apr 2003
    Posts
    3

    Problem with linking a .dll file

    Hi there .

    I've got a problem getting a program to work. I'm quite a newbie so please explain things a bit ok .

    I've got this program code:

    Code:
    #include <windows.h>
    #include <stdio.h>
    #include <iostream.h>
    #include "winio.h"
    
    int main()
    {
      DWORD dwPortVal;
      bool bResult;
    
      bResult = InitializeWinIo();
    
      if (bResult)
      {
        GetPortVal(0x378, &dwPortVal, 4);
        ShutdownWinIo();
        cout << dwPortVal << endl;
        getchar();
        return 0;
      }
      else
      {
        printf("Error.\n");
        exit(1);
      }
    }
    and winio.h looks like this:

    Code:
    #ifndef WINIO_H
    #define WINIO_H
    
    #undef WINIO_DLL
    
    #ifdef WINIO_DLL
    #define WINIO_API _declspec(dllexport)
    #else
    #define WINIO_API _declspec(dllimport)
    #endif
    
    extern "C"
    {
      WINIO_API bool _stdcall InitializeWinIo();
      WINIO_API void _stdcall ShutdownWinIo();
      WINIO_API PBYTE _stdcall MapPhysToLin(PBYTE pbPhysAddr, DWORD dwPhysSize, HANDLE *pPhysicalMemoryHandle);
      WINIO_API bool _stdcall UnmapPhysicalMemory(HANDLE PhysicalMemoryHandle, PBYTE pbLinAddr);
      WINIO_API bool _stdcall GetPhysLong(PBYTE pbPhysAddr, PDWORD pdwPhysVal);
      WINIO_API bool _stdcall SetPhysLong(PBYTE pbPhysAddr, DWORD dwPhysVal);
      WINIO_API bool _stdcall GetPortVal(WORD wPortAddr, PDWORD pdwPortVal, BYTE bSize);
      WINIO_API bool _stdcall SetPortVal(WORD wPortAddr, DWORD dwPortVal, BYTE bSize);
      WINIO_API bool _stdcall InstallWinIoDriver(PSTR pszWinIoDriverPath, bool IsDemandLoaded = false);
      WINIO_API bool _stdcall RemoveWinIoDriver();
    }
    
    extern bool IsNT;
    extern HANDLE hDriver;
    extern bool IsWinIoInitialized;
    
    bool _stdcall StartWinIoDriver();
    bool _stdcall StopWinIoDriver();
    
    #endif
    I'm trying to get it to work, but it won't . I've compiled it with Borland free commandline tools by first compiling it to a .obj file and then linking it with a .lib file I created from a .dll file, using implib. The linker does produce an .exe file, but when running it, it says "program.exe is not a valid Win32 file" (or something similar; I'm actually using a Dutch version of Windows 2000).

    Can anyone please tell me what I'm doing wrong?

    BTW: the program is a program that reads the parallell port of the PC. Since this is not directly possible in Windows 2000, I use WinIo (from www.internals.com) which bypasses the restrictions Windows has. Off course this is just an example program to see if WinIo works, but so far it hasn't.

    I have attached parpoort.zip which contains the files I use.
    Attached Files Attached Files
    Last edited by Krankenstein; 04-28-2003 at 05:12 PM.

  2. #2
    Registered User
    Join Date
    Apr 2003
    Posts
    3
    *kick*

  3. #3
    Registered User
    Join Date
    Apr 2003
    Posts
    3
    Sorry, won't happen again

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Newbie homework help
    By fossage in forum C Programming
    Replies: 3
    Last Post: 04-30-2009, 04:27 PM
  2. Formatting a text file...
    By dagorsul in forum C Programming
    Replies: 12
    Last Post: 05-02-2008, 03:53 AM
  3. help with text input
    By Alphawaves in forum C Programming
    Replies: 8
    Last Post: 04-08-2007, 04:54 PM
  4. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 12:13 AM
  5. Problem with a .dll file
    By GaPe in forum Windows Programming
    Replies: 2
    Last Post: 10-29-2003, 12:20 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21