Writing VS2005 DLL's for non-net Languages?

Miscellaneous Forums/General Discussion/Writing VS2005 DLL's for non-net Languages?

This is probably a stupid question, but I can't find anything in the docs about writing DLL's for non .Net languages. Visual C# 2005 wants to do everything in namespaces and classes, which is fine, but isn't going to give me a DLL I can access in BMax, is it? So I thought, ok, let's try Visual C++ 2005 instead, that'll be better. And apparently that wants to use namespaces and classes for everything too. Is it still possible to write a DLL in either language that BMax / GCC / etc can call? Have a link to an explanation ( or a rough location in the docs if I've missed it ) or something along those lines?

And yes, it does need to be 2005 because I want to use some .Net 2.0 stuff in the DLL, so if it's not possible to do that, there's no point in me writing the DLL.

It's possible you just need to create normal functions with a dll prefix.

example,

Add
#define DLL extern "C" __declspec(dllexport)


after your includes, then to write a function that will be exported do something like this,

DLL int _stdcall MyFunction( float par1 )
{
}


So it's DLL <return_type> _stdcall <Function_Name>(Pars)

This will export them in a slightly mangled form. Which is,

_FunctionName@<SizeOFPars>

To get the size times the number of pars by 4.

So a function like DLL int _stdcall Testfunc(int a,int b)
becomes _Testfunc@8

We're using VC express 2005, and have wrapped Ogre to be accessible in Max, so this is possible.

net 2.0? No idea though.

Ahead of what functions? Don't all functions have to be member or static functions of classes in C#?

I was refering to Visual C++ 2005. I don't think it's possible to link to Managed DLLs in a non-managed language. (Well in c++ maybe, I've heard things. But definitely not max.)

If you do manage it though please let me know! :)

VB.Net & C# only produce managed dlls.
They can be used from unmanaged code(Blitz3d, bmax etc.) by disassembling the managed dll(ildasm), do some manual declarations and then compile it again(ilasm).
However, this is a very tedious task.
I believe someone on this forum was working on a utility for this some time ago.
Try some searching in this forum.

Visual C++ can use some kind of "mixed mode" I think, but I never really got it working.
By "mixed mode" I mean an unmanaged dll using the clr.

Create new project -> win32 project, then Application Settings (bottom in the unusually unusable left options list of wizard page 2) to set preference for dll.

Thanks, that looks right, but the DLL option is blanked out. Do I need something else installed for this to work? The Platform SDK, for instance? I just have the ISO's for VC# and VC++ installed currently. And judging by the size of the PSDK, I'll have to wait for them to release the new one on cd.

If you are using the express edition of VC++ that could(still can?) be downloaded for free, you'll need the Platform SDK as you said and you must also activate the Win32 Console Application template/wizard.
(It's named console Application, but you get the choice to switch during the wizard configuration)

Here are the instructions...
http://msdn.microsoft.com/vstudio/express/visualc/usingpsdk/

I didnt need that:
1. I created a class libary
2. Deleted <projectname>.h
3. coded a simple add function
Listing of <projectname>.cpp
// This is the main DLL file.

#include "stdafx.h"

#define DLL extern "C" __declspec(dllexport)

DLL int _stdcall Add2Ints(int a, int b);

DLL int _stdcall Add2Ints(int a, int b)
{
	return a + b;
}

4. complied
5. opened cmd start>run>cmd
6. cd'ed to mingw\bin
7. typed
pexports <pathtodll><dllname>.dll > <pathtodll><dllname>.def
dlltool -d <pathtodll><dllname>.def -l <pathtodll><dllname>.a

8. whent to the folder where the .dll file was created along with the .a file you create using dlltool
9. Created a bmx file and entered the followig listing
Import "<dllname>.a"

Extern "win32"
	Function Add%(a%, b%) = "_Add2Ints@8"
End Extern

Print add(10, 2500)


And IJW!

Hope this helps you.

[edit]

THESE LINKS NO LONGER WORK DUE TO DELETING THE FILES
Dll Source and BMX source

[further editing]The path of the dll will be the release folder were the .sin folder is located and not the release folder were the .h and .cpp files are

Awesome stuff, Diablo! That works just great. And the instructions were so clear even I couldn't manage to mess up. Thanks a lot for the detailed help.