Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

How to use a CBuilder DLL (that contains classes) from C# 2005?

avmihavmih Member Posts: 1
Hello,

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

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
#include
#pragma hdrstop

#include
#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);
}
[/code]

I tested the dll in [b]Cbuilder 5[/b], 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 [b]C# 2005[/b] 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);

}
}
}
[/code]
and it worked again.

My problem is when I have a [b]class[/b] in my DLL project under CBuilder, I can
Sign In or Register to comment.