Jump to content
Tuts 4 You

Need help converting C + + to Pascal


X-88

Recommended Posts

hi programmer Delphi and C + + i need help converting from C + + to Pascal, because I am not free to call functions in C + + Builder are too sensitive.

I hope you would help me.

thx b4 :)

Code

/*

SunVox engine is distributed under the following BSD-style license:

Copyright © 2002 - 2010, Alex Zolotov <nightradio@gmail.com>

All rights reserved.

Redistribution and use in source and binary forms, with or without

modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice,

this list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice,

this list of conditions and the following disclaimer in the documentation

and/or other materials provided with the distribution.

* The name of the author may not be used to endorse or promote products derived

from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS

"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT

LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR

A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR

CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,

EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,

PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR

PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF

LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING

NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS

SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

*/

#ifndef __SUNVOX_H__

#define __SUNVOX_H__

typedef int (*tsv_open_soundcard)( const char* dev, int freq, int channels );

typedef int (*tsv_close_soundcard)( void );

typedef int (*tsv_init)( int slot );

typedef int (*tsv_deinit)( int slot );

typedef int (*tsv_load)( int slot, const char* name );

typedef int (*tsv_play)( int slot );

typedef int (*tsv_play_from_beginning)( int slot );

typedef int (*tsv_stop)( int slot );

typedef int (*tsv_rewind)( int slot, int t );

typedef int (*tsv_volume)( int slot, int vol );

typedef int (*tsv_get_current_line)( int slot );

typedef int (*tsv_get_current_signal_level)( int slot, int channel );

extern tsv_open_soundcard sv_open_soundcard;

extern tsv_close_soundcard sv_close_soundcard;

extern tsv_init sv_init;

extern tsv_deinit sv_deinit;

extern tsv_load sv_load;

extern tsv_play sv_play;

extern tsv_play_from_beginning sv_play_from_beginning;

extern tsv_stop sv_stop;

extern tsv_rewind sv_rewind;

extern tsv_volume sv_volume;

extern tsv_get_current_line sv_get_current_line;

extern tsv_get_current_signal_level sv_get_current_signal_level;

// for importing entries from dll's..

#define IMPORT( Handle, Variable, Type, Function, Store ) \

Variable = GetProcAddress( Handle, Function ); \

Store = (Type)Variable;

#ifdef SUNVOX_MAIN

tsv_open_soundcard sv_open_soundcard = 0;

tsv_close_soundcard sv_close_soundcard = 0;

tsv_init sv_init = 0;

tsv_deinit sv_deinit = 0;

tsv_load sv_load = 0;

tsv_play sv_play = 0;

tsv_play_from_beginning sv_play_from_beginning = 0;

tsv_stop sv_stop = 0;

tsv_rewind sv_rewind = 0;

tsv_volume sv_volume = 0;

tsv_get_current_line sv_get_current_line = 0;

tsv_get_current_signal_level sv_get_current_signal_level = 0;

int sv_load_dll( void )

{

HMODULE sv_dll;

FARPROC proc;

sv_dll = LoadLibrary( TEXT("sunvox.dll") );

if( sv_dll == 0 )

{

MessageBox( 0, TEXT("sunvox.dll not found"), TEXT("Error"), MB_OK );

return 1;

}

IMPORT( sv_dll, proc, tsv_open_soundcard, "_Z17sv_open_soundcardPKcii", sv_open_soundcard );

IMPORT( sv_dll, proc, tsv_close_soundcard, "_Z18sv_close_soundcardv", sv_close_soundcard );

IMPORT( sv_dll, proc, tsv_init, "_Z7sv_initi", sv_init );

IMPORT( sv_dll, proc, tsv_deinit, "_Z9sv_deiniti", sv_deinit );

IMPORT( sv_dll, proc, tsv_load, "_Z7sv_loadiPKc", sv_load );

IMPORT( sv_dll, proc, tsv_play, "_Z7sv_playi", sv_play );

IMPORT( sv_dll, proc, tsv_play_from_beginning, "_Z22sv_play_from_beginningi", sv_play_from_beginning );

IMPORT( sv_dll, proc, tsv_stop, "_Z7sv_stopi", sv_stop );

IMPORT( sv_dll, proc, tsv_rewind, "_Z9sv_rewindii", sv_rewind );

IMPORT( sv_dll, proc, tsv_volume, "_Z9sv_volumeii", sv_volume );

IMPORT( sv_dll, proc, tsv_get_current_line, "_Z19sv_get_current_linei", sv_get_current_line );

IMPORT( sv_dll, proc, tsv_get_current_signal_level, "_Z27sv_get_current_signal_levelii", sv_get_current_signal_level );

int nf = 0;

if( sv_init == 0 ) nf = 1;

if( sv_init == 0 ) nf = 2;

if( sv_deinit == 0 ) nf = 3;

if( sv_load == 0 ) nf = 4;

if( sv_play == 0 ) nf = 5;

if( sv_play_from_beginning == 0 ) nf = 6;

if( sv_stop == 0 ) nf = 7;

if( sv_rewind == 0 ) nf = 8;

if( sv_volume == 0 ) nf = 9;

if( sv_get_current_line == 0 ) nf = 10;

if( sv_get_current_signal_level == 0 ) nf = 11;

if( nf )

{

MessageBox( 0, TEXT("sunvox.dll: some functions not found"), TEXT("Error"), MB_OK );

return nf;

}

return 0;

}

int sv_unload_dll( void )

{

return 0;

}

#endif

#endif

Sunvox.zip

Edited by X-88
Link to comment

Hi brother

if you are willing to use only those functions provided by sunvox library you don't need to convert the header verbally , well first it is waste of time and may not be good enough , actually I have made one for you to use it as a unit in your delphi projects you just need to include the library with your project :)


unit sunvox;{ comment start
comment end }interfaceuses
windows;const
sunvox = 'sunvox.dll';function sv_open_soundcard(const dev:pchar;freq,channels:integer):integer;stdcall;external sunvox name '_Z17sv_open_soundcardPKcii';function sv_close_soundcard():integer;stdcall;external sunvox name '_Z18sv_close_soundcardv';function sv_init(slot:integer):integer;stdcall;external sunvox name '_Z7sv_initi';function sv_deinit(slot:integer):integer;stdcall;external sunvox name '_Z9sv_deiniti';function sv_load(slot:integer;name:pchar):integer;stdcall;external sunvox name '_Z7sv_loadiPKc';function sv_play(slot:integer):integer;stdcall;external sunvox name '_Z7sv_playi';function sv_play_from_beginning(slot:integer):integer;stdcall; external sunvox name '_Z22sv_play_from_beginningi' ;function sv_stop(slot:integer):integer;stdcall;external sunvox name '_Z7sv_stopi' ;function sv_rewind(slot,t:integer):integer;stdcall;external sunvox name '_Z9sv_rewindii';function sv_volume(slot,volume:integer):integer;stdcall;external sunvox name '_Z9sv_volumeii';function sv_get_current_line(slot:integer):integer;stdcall;external sunvox name '_Z19sv_get_current_linei';function sv_get_current_signal_level(slot,channel:integer):integer;stdcall;external sunvox name '_Z27sv_get_current_signal_levelii';implementationend.

otherwise if you want to translate it verbally just wait a little and I'll make it for you since I don't have free time now, even if it is not that hard it uses a local function that uses GetProcAddress function to get the address foreach function in the library and handles the exceptions.

with the way I used above exceptions are automatically handled.

I hopr it will work ,if you encounter any bug or you need my help I'll be happy to give a hand 8)

sunvox_m_NH.rar

Edited by NewHitman
  • Like 1
Link to comment

Hi brother

if you are willing to use only those functions provided by sunvox library you don't need to convert the header verbally , well first it is waste of time and may not be good enough , actually I have made one for you to use it as a unit in your delphi projects you just need to include the library with your project :)


unit sunvox;{ comment start
comment end }interfaceuses
windows;const
sunvox = 'sunvox.dll';function sv_open_soundcard(const dev:pchar;freq,channels:integer):integer;stdcall;external sunvox name '_Z17sv_open_soundcardPKcii';function sv_close_soundcard():integer;stdcall;external sunvox name '_Z18sv_close_soundcardv';function sv_init(slot:integer):integer;stdcall;external sunvox name '_Z7sv_initi';function sv_deinit(slot:integer):integer;stdcall;external sunvox name '_Z9sv_deiniti';function sv_load(slot:integer;name:pchar):integer;stdcall;external sunvox name '_Z7sv_loadiPKc';function sv_play(slot:integer):integer;stdcall;external sunvox name '_Z7sv_playi';function sv_play_from_beginning(slot:integer):integer;stdcall; external sunvox name '_Z22sv_play_from_beginningi' ;function sv_stop(slot:integer):integer;stdcall;external sunvox name '_Z7sv_stopi' ;function sv_rewind(slot,t:integer):integer;stdcall;external sunvox name '_Z9sv_rewindii';function sv_volume(slot,volume:integer):integer;stdcall;external sunvox name '_Z9sv_volumeii';function sv_get_current_line(slot:integer):integer;stdcall;external sunvox name '_Z19sv_get_current_linei';function sv_get_current_signal_level(slot,channel:integer):integer;stdcall;external sunvox name '_Z27sv_get_current_signal_levelii';implementationend.

otherwise if you want to translate it verbally just wait a little and I'll make it for you since I don't have free time now, even if it is not that hard it uses a local function that uses GetProcAddress function to get the address foreach function in the library and handles the exceptions.

with the way I used above exceptions are automatically handled.

I hopr it will work ,if you encounter any bug or you need my help I'll be happy to give a hand 8)

Hi Bror, ok thank you for taking your time to it.

I just added "Used Sunvox", but the message like the picture that I specified. and I have not added a call

419284_493282404016168_1647714488_n.jpg

I like the simple function call like this

//--------------------------------->

On Show

begin

sv_load_dll();

sv_open_soundcard( 0, 44100, 2 );

if sv_init( 0 ) = 0 then

begin

sv_load( 0, fileName.Sunvox' );

sv_volume( 0, 255 );

sv_play( 0 );

end;

//--------------------------------->

on Destroy

begin

sv_stop( 0 );

sv_deinit( 0 );

sv_close_soundcard;

sv_unload_dll;

end;

Edited by X-88
Link to comment

It is not a big problem actually ,it just the compiler get confused :) since the unit name and the library name is the same

you should change one of them

this


unit sunvox

to


unit // choose another name

or


const
sunvox = 'sunvox.dll'

to


const
sunvox1='sunvox.dll'

I hope it will work

Edited by NewHitman
Link to comment

// for importing entries from dll's..
#define IMPORT( Handle, Variable, Type, Function, Store ) \
Variable = GetProcAddress( Handle, Function ); \
Store = (Type)Variable;#ifdef SUNVOX_MAIN//---------------------------------------------------------------int sv_load_dll( void )
{
HMODULE sv_dll;
FARPROC proc;
sv_dll = LoadLibrary( TEXT("sunvox.dll") );

it seems that in Delphi such as;

type

Form = class(TForm);

blah blah blah

procedure

end;

then a declaration.

function calls between the unit and the other one

What is that?

Edited by X-88
Link to comment

it is just a way to load the library functions at Run-Time not load time by using getProcAddress function believe my way is better and reduces the size of code and much time :)

Edited by NewHitman
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...