views:

552

answers:

2

I have been trying to link to Pb (11.5) generated native Win32 dlls: both from a different Pb app and from a .net (2.0) app. I am aware that registered COM objects are visible to Pb. What I want to do is have Pb (running 11.5 Enterprise) call functions in a native Win32 dll--not COM. I also want to go the other way: I want a Win32 exe (both native and .net) to call a function in a Pb generated dll. I've had limited success.

Scenario 1: Pb generates native Win32 exe & dll.

I created a simple app that includes separate pbl (called shared.pbl) with some trivial functions (including one that returns the string HelloWorld). The project builds to an exe and a separate dll. It works (clicking a button shows the text HelloWorld in a label).

In a separate Pb workspace I create a near identical app, but no shared.pbl. I declare an external function to reference the shared.dll from the first workspace:

 function int GetSystemMetrics( int index ) library "user32.dll";
 function int f_rtn_int( int number ) library "shared.dll";

running the app--clicking a button tied to GetSystemMetrics() works. Clicking a second button to access shared.dll fails with the "Error calling external function ..." message.

The only way I have been able to get the second app to work is to add the shared.dll under the library list tab on the target properties. However this seems to cause the contents of the dll to be embedded in the generated exe--I can delete shared.dll and the second app runs just fine!

How do I reference an external Win32 dll in Pb w/o having the dll embedded in the generated Pb code? Remember, shared.dll was generated by Pb in a separate workspace.

Scenario 2: .Net exe accesses a Pb generated dll

I next created a simple .net app (.net v2.0, vs2005) with parallel functionality to the Pb apps. I reference shared.dll:

  [DllImport( "user32.dll" )]
  static extern int GetSystemMetrics( int smIndex );
  [DllImport( "shared.dll" )]
  static extern string f_get_hello_world();

and try to call the HelloWorld function and I get the .net error:

 Unable to find an entry point named 'f_get_hello_world' in DLL 'shared.dll'

Using an editor/dissasembler I discover that the function name has been mangled into "_getVtableInfo_f_get_hello_world@12". I tried different naming variations on the declaration and call w/o luck.

Is it possible to reference a native Win32 dll created by Pb from another language (c++, c#)? If so, how?

+1  A: 

Basically, you don't. You can create a COM object project, or with 11 or 11.5 you can create a .NET assembly. The DLLs created by "native" generation aren't standard Windows DLLs, so can't be called with normal DLL methods.

Good luck,

Terry.

Terry
Thanks! I was beginning to suspect this. We're desparate to move to .Net (where I'm from) but must find a piecemeal way to do so. Can't afford an all out re-write.
erhm
A: 

If Pb obeys "extern C" on your function definitions, then it should export them with unmangled names.

For your other question of why it seems to be OK to delete the dll and the program still runs, I can only give a slightly possible guess: Look to see if some tool made another copy of the dll and it still exists.

Windows programmer