Thread: This stupid binary dll isnt working...

  1. #1
    Registered User
    Join Date
    Mar 2006

    This stupid binary dll isnt working...

    First off im a total newbie when it comes to C++, but i was making a binary functions dll in C++ and well it only returns '0' back to me.

    //Define export macro
    #define export extern "C" __declspec( dllexport )
    #include <iostream>
    #include <fstream>
    #include <windows.h>
    using namespace std;
    ifstream::pos_type size; //Size of file
    char * memblock; //Memory "Storage"
    char * pEnd; //End char
    double ret; //Variable helps with conversion
    export double readFile(PCHAR filepath)
           ifstream file (filepath, ios::in|ios::binary|ios::ate);
           if (file.is_open())
                              size = file.tellg();
                              memblock = new char [size];
                              file.seekg (0, ios::beg);
                     (memblock, size);
                              ret = strtod(memblock,&pEnd); //Damnit! Now to convert :(
                              return ret; //Return PLEASE! lol
                 return 0;
    The program i use ONLY accepts double and null arguments to be passed back and forth through the dll, so i had to convert the file's binary data into 'double' but like i said i only get '0' in return...

    So can anyone help with this? Im pretty sure its the dll thats causing the problem, but im not sure.


  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    According to this, strtod() has 3 parameters and you only pass it two.
    My guess is that it barfs on the garbage pointer just lying around on the stack.

    Didn't your compiler issue any kind of warning for this, or did you just ignore the warnings.
    Oh wait, it can't tell you anything because you didn't include all the proper header files.

    > memblock = new char [size];
    You need to delete this as well.

    I also can't see a reason why all your vars are global.
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Binary Search Tree in DLL
    By Silvio in forum C Programming
    Replies: 6
    Last Post: 05-10-2009, 11:39 AM
  2. arrays vs lists? And containers in general!
    By clegs in forum C++ Programming
    Replies: 22
    Last Post: 12-03-2007, 02:02 PM
  3. Tutorial review
    By Prelude in forum A Brief History of
    Replies: 11
    Last Post: 03-22-2004, 09:40 PM
  4. Request for comments
    By Prelude in forum A Brief History of
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM
  5. binary
    By webturtle0 in forum A Brief History of
    Replies: 52
    Last Post: 12-05-2002, 02:46 AM