cancel
Showing results for 
Search instead for 
Did you mean: 

Error in Calling External Function

Former Member
0 Kudos
844

Hi,

We are migration PowerBuilder Legacy application which is currently built on PB11 and Win XP environment.

Migrating to PowerBuilder 12.5 (12.5.2 Build 5602) Classic for Windows 7.

We are using DLLs which is developed in VC++.

Migration is smooth using the Automated Migration Tool provided by PowerBuilder.

When we tried to run the application getting a error "Error In calling the external function.....", which is declared in Local External Functions and error occured on Function call.

I wrote a sample program to call the DLLs and I declared in Global External Functions (Not Intentionally )... Strange I was getting a different error "Bad Runtime reference....", I build the sample application and Ran it in Release mode It worked fine.

Can anyone help me what is happening and will be greatful if anyone could help me in resolving the issue.

Running the application Deployed in PB11 is working fine in Win 7 on this DLL Perspective.

-- Declaration --

Function Integer encrypt(String InputData, String EncKey, String SeedIn, ref string Encrypteddata) library "CRYPTDLL.dll" alias for "encrypt;Ansi"

-- Error While calling  below line --

li_rtn = encrypt(ls_pwd, ls_key, ls_seed, ls_encpwd)

Regards,

Vinu

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

You need to see that the Exports of the DLL still match what they're supposed to be.

http://www.dependencywalker.com/

This program allows you to see the exports of a DLL file. If you aren't allowed to run it, see if your DLL guys have a program called dumpbin, it'll let you see the exports too (dumpbin /exports cryptdll.dll).

Open your problem DLL with the program (File/Open)

The lower window on the right has a list of exports in it. If the function that's not working has an "@" towards the end of it, it's been "mangled" and is a C++ style declaration. If it's plain, then you should be able to call it.

Check to see that cryptdll.dll doesn't exist in more than one place on your machine, or, if it does, that they're all the same version.

Check with your DLL developers, make sure your PB function declaration matches 100% to what you're calling. Under some circumstance an Int in C/C++ might actually be a Long in PB (it depends on how the C/C++ compile was done). I've had a few instances where the function worked most of the time, but failed on occasion and it turned out to be a return value that was mismatched and causing stack corruption, but not always to the extent that it was detrimental to the system.

former_member329524
Active Participant
0 Kudos

If you have differences between runtime and design-time behaviour, is it possible that you have several CRYPTDLL.dll files on your disk and one of them is in path and the other is in the runtime directory?

We have made numerous such migrations and never encountered problems like yours.

Former Member
0 Kudos

Hi Arcady,

Maintaining both in same path, Just making a Build and running the application from same folder.

I have given the complete path of the library to ensure that its taking from same and right path. Still same behaviour.

 

-- Declaration --

Function Integer encrypt(String InputData, String EncKey, String SeedIn, ref string Encrypteddata) library "C:\Source\TestApp\CRYPTDLL.dll" alias for "encrypt;Ansi"

-- Error While calling  below line --

li_rtn = encrypt(ls_pwd, ls_key, ls_seed, ls_encpwd)

Regards,

Vinu

former_member329524
Active Participant
0 Kudos

Hi, Vinu

Very difficult to examine without the test app....

Too bad SAP does not allow uploading of PB projects. It is especially frustrating, since in my experience calling generic external functions works fine.

Just to make sure, can you try a different external function?

For example, add this to global external functions:

//-----------------------------------

FUNCTION long GetSystemMetrics(long nIndex ) LIBRARY "USER32.DLL"

//-----------------------------------

Then, try running the following code:

//---------------------------

long ll_Height

ll_Height  =  GetSystemMetrics(4) // return  Height of windows caption

//----------------------------

Does this function work, or also crash?

former_member190719
Active Contributor
0 Kudos

Try using Google Drive to share it.

Former Member
0 Kudos

Hi Arcady,

This is a Windows API and is working fine. The DLLs which I mentioned is a Custom DLL.

Regards,

Vinu

Former Member
0 Kudos

Hi Bruce,

I cannot share the code because its in a secured Network. Its highly impossible to share the DLLs.

Regards,

Vinu

former_member329524
Active Participant
0 Kudos

OK, so, we are making progress - you can make calls to at least some external functions.

So, now we need to figure out why you cannot call this specific function from this specific dll.

The problem is either with the dll, with the function, or with the way you make the call to it.

So, lets employ elimination method.

1. Can you create another function in this dll? If yes, create a function, which accepts one Long parameter and returns it right back to the caller.

2. If it works, then create another empty function, which has the same parameters as your source function, but has no code in it. If it also works, then the problem is in the dll itself.

3. If point 2 fails, then the problem is in the method that you make the call. I would suggest to examine 2 possible failure points: the REF part (try to call it with REF as well) and the string/ansi part.

Can you go through the above motions and see where you fail?

Former Member
0 Kudos

Hi Vinu;

1) You are not trying to run your application and the custom DLL from a a network server are you? This would invoke TRUST issues with newer O/S's like W7.

2) I would like to suggest adding a TRY..CATCH around the external DLL call and seeing if the exception handler can give you some better diagnostic information.

regards ... Chris

Former Member
0 Kudos

Hi Arcady,

Sure I'll try to try to do these steps you mentioned. This DLL is working fine after the build when declared in Global External Functions, If I'm not wrong the DLL and the Calling method is perfect enough to run the task.

Regards,

Vinu

Former Member
0 Kudos

Hi Chris,

We are working on both virtual Machine and Physical Machine, got the same behavior in both the environments.

I tried to register the DLL using regsvr32, but I couldn't. I can give you the error details which I got while registering.

I tried to Sign the DLL using SignTool to make it Trustable. I failed there too..

I will try to use the Exception handling  and update you.

Please keep posting the solutions and If possible help me in Signing / registering the DLL.

Thanks & Regards

Vinu

former_member190719
Active Contributor
0 Kudos

Are you sure that the DLL in question doesn't have dependencies on other DLLs that you haven't deployed?  You might use DependencyWalker to determine if there are missing referenced DLLs.

Former Member
0 Kudos

Hi Bruce,

We use around 4 DLLs in this application. I have mentioned only 1 of them, whereas all the DLLs have this same issue.

Yes, there is a dependency of a DLL over another DLL. But we have all the DLLs in place.

The DLL I mentioned (CRYPTDLL.Dll) doesn't have any dependencies.

Regards,

Vinu