Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to use a Cbuilder DLL that contains classes from C# 2005

Status
Not open for further replies.

avmih

Programmer
Feb 5, 2009
1
RO
Hello,

Please help me to use a CBuilder DLL that contains classes from Visual Studio C# 2005, I have problems with the underscores.

I used a well-known example which creates a DLL in Cbuilder 5 (use VCL set, source C++) and I named it DLLProject.dll:

Code:
#include <vcl.h>
#include <windows.h>
#pragma hdrstop

#include <windows.h>
#pragma argsused

double BoxArea(double L, double H, double W);
double BoxVolume(double L, double H, double W);

extern "C" __declspec(dllexport)void BoxProperties(double Length, double Height,
                                    double Width, double& Area, double& Volume);

BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fwdreason, LPVOID lpvReserved)
{
        return 1;
}
//---------------------------------------------------------------------------
double BoxArea(double L, double H, double W)
{
    return 2 * ((L*H) + (L*W) + (H*W));
}
//---------------------------------------------------------------------------
double BoxVolume(double L, double H, double W)
{
    return L * H * W;
}
//---------------------------------------------------------------------------
void BoxProperties(double L, double H, double W, double& A, double& V)
{
    A = BoxArea(L, H, W);
    V = BoxVolume(L, H, W);
}

I tested the dll in Cbuilder 5, using C convention and Generate underscores On, and it worked.

Next step I rebuild the dll this time using Generate underscores Off, and I called this dll from C# 2005 as in the following example:

Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace UnManaged
{
    public partial class Form1 : Form
    {

        [DllImport("DLLProject.dll")]
        static extern void BoxProperties(double L, double H, double W,
                                 double[] A, double[] V);
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            double myLength=2, myHeight=3, myWidth=4;
            double[] myArea = new double [1];
            double[] myVolume = new double [1];
            
            BoxProperties(myLength, myHeight, myWidth, myArea, myVolume);

        }
    }
}
and it worked again.

My problem is when I have a class in my DLL project under CBuilder, I can’t just build it with Generate underscores unset because I receive a link error:

Unresolved external ‘_Class Create’ referenced from …

How can I get rid off the underscores from my CBuilder dll if I build it with Generate underscores set, in order to use it in my C# code
?
Or other solution to resolve this issue?

Thank you
 
Unresolved external '_Class Create' referenced from ...
That's a standard C++ linker error. You need to make sure you link the correct library(ies). See if this site can help.



James P. Cottingham
I'm number 1,229!
I'm number 1,229!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top