How?

Blitz3D Forums/Blitz3D Userlibs/How?

Jerome Squalor(Posted 2007) [#1]
Could some one give me a tutorial on how to make User Libs?
I know nothing of C++ coding so REALLY detailed if can.
(seriously though, I know NOTHING, no terms, know commands, in fact i have no idea how a C++ program would even be started. NOTHING)

Thnx.


Mortiis(Posted 2007) [#2]
It is from the specifications Mark wrote on the Specs and utils tab from the community.

Example
-------

Ok, here's a little C++ example, as it would appear in VisualC.

First, we write the DLL:

//demo.dll
//
#include <math.h>
#include <string.h>
#include <stdlib.h>

#define BBDECL extern "C" _declspec(dllexport)
#define BBCALL _stdcall

//returns a float and has 6 float parameters
BBDECL float BBCALL VecDistance( float x1,float y1,float z1,float x2,float y2,float z2 ){
	float dx=x1-x2,dy=y1-y2,dz=z1-z2;
	return sqrtf( dx*dx+dy*dy+dz*dz );
}

//returns a string and has one string parameter
BBDECL const char * BBCALL ShuffleString( const char *str ){
	static char *_buf;

	int sz=strlen(str);

	delete[] _buf;
	_buf=new char[ sz+1 ];
	strcpy( _buf,str );
	
	for( int k=0;k<sz;++k ){
		int n=rand()%sz;
		int t=_buf[k];_buf[k]=_buf[n];_buf[n]=t;
	}

	return _buf;
}
After building this, the resultant 'demo.dll' should be placed in the userlibs directory.

Now, we also need to create a 'demo.decls' file, describing the functions in our dll. This file
is also placed in the userlibs directory:

.lib "demo.dll"
VecDistance#( x1#,y1#,z1#,x2#,y2#,z2# ):"_VecDistance@24"
ShuffleString$( str$ ):"_ShuffleString@4"

...Voila! The next time Blitz is started up, the new commands appear within the IDE and can be used.



Jerome Squalor(Posted 2007) [#3]
How do you make the .decl file?


Moraldi(Posted 2007) [#4]
With notepad...


Jerome Squalor(Posted 2007) [#5]
What? Its not a code


Jerome Squalor(Posted 2007) [#6]
would the code that mortiis gave work in Dev C++?


Moraldi(Posted 2007) [#7]
Yap, its pure ANSI C


Pinete(Posted 2007) [#8]
Please next time try to be more specific with the title of the post... "how?"

All the best,


Jerome Squalor(Posted 2007) [#9]
Oh, he he he...sorry.