Thread: Need help with basic C DLL

  1. #1
    Registered User
    Join Date
    Jan 2017
    Posts
    3

    Need help with basic C DLL

    Hello, I'm not sure what I'm doing (i study math/physics not CS) and need some help. I am trying to write a DLL in C such that I can pass in two parameters and return a double. Here is the code:

    Code:
    #pragma once
    #include <stdio.h>
    #define DLLF _declspec(dllexport)
    
    DLLF double FractalPriceReturn(double price, bool frac)
        {
            double fracprice = price;
            bool fracflag = frac;
            if (fracflag == 2)
            {
                return fracprice;
            }
            else return 0;
        }
    ////////

    The software (a neural network) I'm using to call the DLL selects the file (the DLL) that I want to use but as soon as I do that it crashes my neural network software. Am I saving the program incorrectly? The code is built in VS. Is there something wrong with my code? (It's been a while). Thanks for any responses.

  2. #2
    Registered User
    Join Date
    May 2015
    Posts
    56
    Hello,

    Isn't a bool just true or false?

    Regards

  3. #3
    Registered User MutantJohn's Avatar
    Join Date
    Feb 2013
    Posts
    2,665
    Would you mind elaborating on "crashes my neural network"? Are you able to compile and successfully link against your DLL?

  4. #4
    Registered User MutantJohn's Avatar
    Join Date
    Feb 2013
    Posts
    2,665
    Quote Originally Posted by mad-hatter View Post
    Hello,

    Isn't a bool just true or false?

    Regards
    Also, this. You're declaring a bool and then comparing it to the number two which will never be equal. Ever. In fact, you shouldn't even be doing such mismatched typed comparisons. I suggest you turn up your compiler warnings.

  5. #5
    Registered User
    Join Date
    Jan 2017
    Posts
    3
    Yea I see the logic error. What I meant to say is that if the NN passes a value of 2 then flag true, so the bool should actually be int in the function parameters. Anyways, the moment I try and select the file (my DLL) the NN tells me that an unexpected error has occurred and I can choose to send an error report. I've already sent an error report to the creators of the NN. And then after that the program closes. Could anyone just show me what a simple DLL would look like? As far as I can tell I do not need any windows functions or anything like that.
    Last edited by NetMage; 01-16-2017 at 07:21 PM.

  6. #6
    Registered User
    Join Date
    Jan 2017
    Posts
    3
    I just need to see the structure/syntax in C, of what a DLL looks like that takes 2 parameters and returns a value. Could be adding two numbers, that would work just fine. THanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Some basic Q's about C#
    By manasij7479 in forum Tech Board
    Replies: 35
    Last Post: 04-24-2011, 03:10 AM
  2. need some help with basic C++
    By ramonnie in forum C++ Programming
    Replies: 6
    Last Post: 06-28-2007, 11:15 AM
  3. basic ms-dos sim, need help
    By JOlszewski in forum C++ Programming
    Replies: 1
    Last Post: 01-13-2006, 03:55 PM
  4. vc++ basic help
    By gooddevil in forum C++ Programming
    Replies: 2
    Last Post: 05-16-2004, 11:01 AM
  5. A Basic BNF for C
    By starX in forum C Programming
    Replies: 2
    Last Post: 05-04-2002, 11:56 PM

Tags for this Thread