This stupid binary dll isnt working...

This is a discussion on This stupid binary dll isnt working... within the C++ Programming forums, part of the General Programming Boards category; First off im a total newbie when it comes to C++, but i was making a binary functions dll in ...

  1. #1
    Registered User
    Join Date
    Mar 2006
    Posts
    3

    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.

    Code:
    //Define export macro
    #define export extern "C" __declspec( dllexport )
    
    //Headers
    #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);
                              file.read (memblock, size);
                              file.close();
                              
                              ret = strtod(memblock,&pEnd); //Damnit! Now to convert :(
                              return ret; //Return PLEASE! lol
           }else{
                 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.

    Thanks,
    -Steve

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

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, 01:02 PM
  3. Tutorial review
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 11
    Last Post: 03-22-2004, 08:40 PM
  4. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 09:33 AM
  5. binary
    By webturtle0 in forum A Brief History of Cprogramming.com
    Replies: 52
    Last Post: 12-05-2002, 01:46 AM

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