error C2664 when calling dll

This is a discussion on error C2664 when calling dll within the C++ Programming forums, part of the General Programming Boards category; Hello C Programmers, I'm trying to call a Dll from a C++ project that should be compliled into a Dll. ...

  1. #1
    Registered User
    Join Date
    Oct 2012
    Posts
    2

    error C2664 when calling dll

    Hello C Programmers,
    I'm trying to call a Dll from a C++ project that should be compliled into a Dll.
    Code:
    // DLL handle
    HINSTANCE DLLHandle = NULL;

    Code:
    unsigned char CANdoInitialise(void)
    {
      unsigned char Status;
        HINSTANCE DLLHandle = NULL;
      if (DLLHandle == NULL)
        DLLHandle = LoadLibrary(("CANdo.dll"));
    
      if (DLLHandle != NULL)
      {
        // DLL loaded, so map functions
        if (CANdoMapFunctionPointers())
        {
          // One or more functions not mapped correctly, so deallocate all resources
          CANdoFinalise();
          Status = FALSE;  // Error
        }
        else
          Status = TRUE;  // OK
      }
      else
        Status = FALSE;  // Error
    
      return Status;
    }
    when i try to compile it it get the following error.

    Code:
    c:\users\mhhansen.dse\documents\visual studio 2008\projects\cando dll driver\cando dll driver\cando dll driver.cpp(101) : error C2664: 'LoadLibraryW' : cannot convert parameter 1 from 'const char [10]' to 'LPCWSTR'
    1>        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
    i have tried to search for this probleme using google, but can't seem to find a solution for the probleme.

    /Marck Hansen

  2. #2
    Registered User
    Join Date
    Oct 2012
    Posts
    2
    I might have solve the probleme by doing the following:

    #include <tchar.h>

    and:

    DLLHandle = LoadLibrary(_T("CANdo.dll"));

    is this correct?

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,499
    Looks good.
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  4. #4
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,548
    FYI, while this is indeed C++, it is also Windows programming.
    As such, it would be better to put these kinds of questions in the Windows programming forum. It might help you get better replies.
    EDIT: This does not mean Salem's reply is bad.
    It just means that you might avoid some people who have little experience with Windows programming which is much different from C++ programming.
    Plus there may be people who are most active in the Windows programming forum.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. error c2664???
    By time4f5 in forum C Programming
    Replies: 10
    Last Post: 05-10-2011, 05:24 AM
  2. error C2664
    By carolsue2 in forum C++ Programming
    Replies: 1
    Last Post: 03-20-2006, 10:17 AM
  3. Need Help on C2664 error
    By jamez05 in forum C++ Programming
    Replies: 8
    Last Post: 10-28-2005, 12:40 PM
  4. Error C2664
    By carisma36 in forum C++ Programming
    Replies: 1
    Last Post: 12-11-2004, 02:22 AM
  5. C2664 Compile Error
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 04-18-2002, 12:43 AM

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