Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6591823
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:28:30+00:00 2026-05-25T17:28:30+00:00

Hi I want to call functions from a C dll to C++/CLI. The C

  • 0

Hi I want to call functions from a C dll to C++/CLI. The C functions are declared extern. I followed this tutorial for linking the dll: http://social.msdn.microsoft.com/Forums/en/Vsexpressvc/thread/84deabaa-ae82-47cc-aac0-592f5a8dfa22
and then in my C++/CLI dll I have the following:

    // testWrapper.h
#pragma once 
using namespace System;
namespace testWrapper { 
    extern "C" int GtoCalcImpliedVolatility2(
           double  premium,
           int     optionType,
               double  underPrice,
           double  strike,
           double  yearsToExpiry,
           double  yearsToPayment,
           double  volGuess,
           double  discountRate,
               double  dividendRate,
           double  growthRate,
           double *impliedVol);
    public ref class MyNamesSplitterClass
    {
    private:
    public:


      int TestSomething()
      {
          double vol;
          int _status = GtoCalcImpliedVolatility2(
                                0.098328, //premium
                                 'P', //optionType
                                 0.950000, //underPrice
                                 1.050000, //strike
                                 0.900000, //yearsToExpiry
                                 0.95, //yearsToPayment
                                 0.01, //volGuess
                                 0.02, //discountRate
                                 0.03, //dividendRate
                                 0.04,//growthRate
                                 &vol);
      }
    };
}

I know that I’m supposed to only give signatures in the .h and then write function code in .cpp but for the sake of testing, I’m writing it in the same place.
These are the errors I get:

Error   3   error LNK1120: 2 unresolved externals   (etc...)

Error   1   error LNK2028: unresolved token (0A000006) "int __cdecl testWrapper::GtoCalcImpliedVolatility2(double,int,double,double,double,double,double,double,double,double,double *)" (?GtoCalcImpliedVolatility2@testWrapper@@$$FYAHNHNNNNNNNNPAN@Z) referenced in function "public: int __clrcall testWrapper::MyNamesSplitterClass::TestSomething(void)" (?TestSomething@MyNamesSplitterClass@testWrapper@@$$FQ$AAMHXZ)   

Error   2   error LNK2019: unresolved external symbol "int __cdecl testWrapper::GtoCalcImpliedVolatility2(double,int,double,double,double,double,double,double,double,double,double *)" (?GtoCalcImpliedVolatility2@testWrapper@@$$FYAHNHNNNNNNNNPAN@Z) referenced in function "public: int __clrcall testWrapper::MyNamesSplitterClass::TestSomething(void)" (?TestSomething@MyNamesSplitterClass@testWrapper@@$$FQ$AAMHXZ)

I have tried looking them up but can’t find much information about them apart from the fact that they are due to bad linking…

UPDATE: Organisation of projects…

So for my c++/cli project I have written a .hpp as follows that includes my 880+ headers:

extern "C" {

#include "accrued.h"
...
#include "gtobf.h" // this contains GtoCalcImpliedVolatility2
...
#include "../includep/zcsmthp.h"

}

the following is gtobf.h:

    #ifndef ALIB_GTOBF_H
    #define ALIB_GTOBF_H

    #include "cgeneral.h"
    #include "optprop.h"                   /* TOptionProperties */
    #include "cmemory.h"                   /* FREE macro */
    #include "rtnewton.h"                  /* TObjectFunc */


    #ifdef __cplusplus
    extern "C"
    {
    #endif

    /*f
     * Calculates volatility implied by the price of a given option.
     */
//#define GTO_EXPORT(type) __declspec(dllexport) type
    GTO_EXPORT(int )  GtoCalcImpliedVolatility2( 
       double  premium,                    /* (I) Option premium */
       int     optionType,                 /* (I) GtoOPTION_PUT/GtoOPTION_CALL */
       double  underPrice,                 /* (I) Underlyer price */
       double  strike,                     /* (I) Strike/exercise price */
       double  yearsToExpiry,              /* (I) Years to option's expiry */
       double  yearsToPayment,             /* (I) Years till option pays off */
       double  volGuess,                   /* (I) Volatility guess (.06 for 6%) */
       double  discountRate,               /* (I) Discount rate (ann. compound) */
       double  dividendRate,               /* (I) Dividend rate (ann. compound) */
       double  growthRate,                 /* (I) Growth rate (ann. compound) */
       double *impliedVol);                /* (O) Implied Volatility */

    //...other functions

    #ifdef __cplusplus
    }
    #endif

    #endif    /* ALIB_GTOBF_H */

Then in my c++/cli wrapper I include my all.hpp that includes all the other headers…
With all this I am still getting the errors.

I am sure that the function is exported because I have used the dll from C# using P/Invoke…

!!!!!!!!!!!!!!! EDIT:

I had not indicated the correct path for the lib… Now I have sorted that out and I am getting a LNK1104 error saying it can’t open my .lib

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T17:28:31+00:00Added an answer on May 25, 2026 at 5:28 pm

    Solution:

    In the C++ project:

    • In C/C++ -> General add the directory containing the headers to include
    • In Linker -> General Add the directory of the .lib file
    • In Linker -> Input -> Additional Dependencies add the name of the .lib file

    And finally, in my C++ code, I didn’t need to redefine the C function. The following shows my code:

    .cpp:
    // This is the main DLL file.

    #include "stdafx.h"
    
    #include "FinLib.h"
    
    namespace FinLib {
    
        void Class1::CalcImpliedVolatility()
          {
              double volat = 0.0;
              int _status = GtoCalcImpliedVolatility2(//defined in all.h(dll)
                                    0.098328, //premium
                                     'P', //optionType
                                     0.950000, //underPrice
                                     1.050000, //strike
                                     0.900000, //yearsToExpiry
                                     0.95, //yearsToPayment
                                     0.01, //volGuess
                                     0.02, //discountRate
                                     0.03, //dividendRate
                                     0.04,//growthRate
                                     &volat);
              Console::WriteLine(volat);
          }
    }
    

    .h:

    // FinLib.h
    
    #pragma once
    #include "all.hpp" //this line I will move to stdafx.h after (includes all the headers)
    using namespace System;
    
    namespace FinLib {
    
        public ref class Class1
        {
        public:
    
          void CalcImpliedVolatility();
    
        };
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to call some Nt function from ntdll.dll, I'm doing that like this
I want to call a function from a .NET DLL (coded in C#) from
I have a native regular C++ Dll which I want to call from C#
I have an dll written in C++, and I want to call it from
I want to call a c# function from my javascript function. I have a
I want to call a controller function from a view. Is that possible in
I want to call a copyFile function from within the source file to be
I want to call my facebook send dialog function from code behind : The
Summary I want to be able to call a JavaScript function from a Flex
When my interface rotates i want to call certain functions. How can I do

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.