Interfacing a _stdcall 32bit dll (Asio driver)

Just starting out? Need help? Post your questions and find answers here.
eriansa
Enthusiast
Enthusiast
Posts: 277
Joined: Wed Mar 17, 2004 12:31 am
Contact:

Interfacing a _stdcall 32bit dll (Asio driver)

Post by eriansa »

I can natively interface a 64 bit asio driver without a problem :D

I can also interface a 32 bit asio driver through a C wrapper dll : this dll simply exports the Asio functions as STDMETHODIMP. 8)
(STDMETHODIMP is a COM return type, which expands to HRESULT __export __stdcall. It's declared in winnt.h)

But I can't natively interface the 32 bit asio driver. (ESP and EAX at least become useless after the first method call)

Anybody any idea how to safely push and pop the right registers???

Tia!

Btw : I've made my first VST plugin in PB (both 32 and 64 bit) and it works like a charm : see http://www.raxntrax.com/modulys
User avatar
oreopa
Enthusiast
Enthusiast
Posts: 284
Joined: Sat Jun 24, 2006 3:29 am
Location: Edinburgh, Scotland.

Re: Interfacing a _stdcall 32bit dll (Asio driver)

Post by oreopa »

Hey erisana,

A couple of questions... Any plans to release that VST template/skeleton? I am also interested if you would ever release the Rax'n'Trax source, or even consider cutting it down to make a very simple ASIO/VST host source available for PB?

Thanx in advance.

(My 64th post \o/ C= Forever! :D )

PS: Sorry I cant help, didn't mean to hijack ;)
Proud supporter of PB! * Musician * C64/6502 Freak
User avatar
idle
Always Here
Always Here
Posts: 6179
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Interfacing a _stdcall 32bit dll (Asio driver)

Post by idle »

if your interfaces are working on x64 and linux x86/x64
and not on windows x86 it will be a thiscall, so you would have to patch the asm

Code: Select all

CompilerIf #PB_Compiler_OS = #PB_OS_Windows  And SizeOf(Integer) = 4  ;tested x86 
   
  !Macro CALL proc {
   !cmp [p_cppobjptr], 0
   !je @f
   !push edx 
   !mov edx, dword [p_cppobjptr]
   !mov edx, [edx]
   !cmp edx, eax 
   !pop edx 
   !jne @f
   !pop eax
   !mov eax, dword [p_cppobjptr]
   !mov ecx, eax 
   !mov eax,[eax]
   !@@:
   !call proc   
   !}  
   
 Global *cppobjptr

  Macro SetCppObj(pInterface)
   *cppobjptr = pInterface 
 EndMacro   
 
 ;call SetCppOjb with the *objectptr so it knows to patch it to a this call 
CompilerElse 
   
   Macro SetCppObj(pInterface)
  EndMacro   
   
CompilerEndIf   


;eg 
*Device.IDevice=CreateDevice()
If *Device
     SetCppObj(*Device) ;set c++ class interface to use the this call patch        
             
    *Device\foo() ;call functions  
    
     SetCppObj(0) ;set to zero to turn off the thiscall patching 

endIf   
      
Windows 11, Manjaro, Raspberry Pi OS
Image
eriansa
Enthusiast
Enthusiast
Posts: 277
Joined: Wed Mar 17, 2004 12:31 am
Contact:

Re: Interfacing a _stdcall 32bit dll (Asio driver)

Post by eriansa »

@idle
Thanks for your effort, but I am 100% sure it is a stdcall. Like I said it works without the C warpper on x64. The strange thing is, that on x86, a first call to a method works, but every second call (to the same or to another method) results in an invalid memory address. EAX is screwed...
Oh well, I'll just keep using the C wrapper dll...

@oreopa
I am planning to make a website "Making VST in PB" / "Making use of Asio in PB" / "Hosting VST's in PB".
User avatar
idle
Always Here
Always Here
Posts: 6179
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Interfacing a _stdcall 32bit dll (Asio driver)

Post by idle »

do you have a link to the libraries or their headers ?
Windows 11, Manjaro, Raspberry Pi OS
Image
eriansa
Enthusiast
Enthusiast
Posts: 277
Joined: Wed Mar 17, 2004 12:31 am
Contact:

Re: Interfacing a _stdcall 32bit dll (Asio driver)

Post by eriansa »

idle wrote:do you have a link to the libraries or their headers ?
I don't think I can post it publicly due to Steinberg's license agreement, but you can get the ASIO SDK from their website.

http://www.steinberg.net/en/company/developer.html

You can find a Delphi translation here : http://www.axiworld.be/asio.html
You will notice that Delphi also required a C wrapper dll (openasio.dll) because of the stdcall convention.

I do exactly the same in PB x86 (use wrapper), in PB x64 there's no need for it.
But again, everything works!

I just want to find out why in x86 I need this wrapper...
I can only think that PB works exactly like Delphi in this matter. (x86 assuming cDecl).

If that's the case it would be great to have something like
Interface/EndInterface - InterfaceStd/EndInterfaceStd,
User avatar
oreopa
Enthusiast
Enthusiast
Posts: 284
Joined: Sat Jun 24, 2006 3:29 am
Location: Edinburgh, Scotland.

Re: Interfacing a _stdcall 32bit dll (Asio driver)

Post by oreopa »

eriansa wrote:@oreopa
I am planning to make a website "Making VST in PB" / "Making use of Asio in PB" / "Hosting VST's in PB".
eriansa: Thx for the reply, I'll be keeping a keen eye out for that - look forward to it. Cheers. Also good luck with the plugin, it looks interesting.
Proud supporter of PB! * Musician * C64/6502 Freak
Thorium
Addict
Addict
Posts: 1312
Joined: Sat Aug 15, 2009 6:59 pm

Re: Interfacing a _stdcall 32bit dll (Asio driver)

Post by Thorium »

eriansa wrote: I just want to find out why in x86 I need this wrapper...
I can only think that PB works exactly like Delphi in this matter. (x86 assuming cDecl).
PB uses StdCall. You could try if it works if you call it with cDecl.
Take a look at PrototypeC.
Post Reply