Click here to Skip to main content
15,884,031 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
This is a newbie question. I have a third party DLL that I'm working with. I'm using other functions inside the DLL that are working fine but they are only returning a number indicating whether it worked or not. They have another function that should get multiple results from the function but I'm not sure how to retrieve them. Here is the documentation on the function. Whenever I try to call the function my program blows up. And if I call the third party they basically say that it's a VB problem and they can't support it. Any ideas.

int queryActiveClients(char *returnInfo, int *rtnInfoLength);

Return a list of the environments that are currently registered (i.e. running) on the Client.

Parms:
Buffer to hold the return information
Pointer to the length of the buffer

Returns:
0 if successful
-1 if Client is not running
-2 if application is invalid (not allowed to send commands)
-3 if buffer is too small to hold return info.  In this case, rtnInfoLength contains the buffer size needed, and returnInfo contains an empty string.
-4 if command is incorrect (syntax or semantics)
Posted
Comments
walterhevedeich 31-Mar-11 9:24am    
need some error details. and more details(technical, code snippets for example) on what exactly are you doing.

The function should return the active list of clients running as there could be multiples. I have a feeling I'm declaring the Function incorrectly but I'm not sure how to return multiple results as I'm a total newbie to vb.net but I've made a ton of progress so far.

I get the following error:

Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

Here is the code i'm trying to use to call the function
Dim Hostname As String
Dim bufferlength As Integer
Hostname = " "
bufferlength = 0
rtnVal = queryActiveClients(Hostname, bufferlength)

Here is where I declared the DLL function.

Declare Function queryActiveClients Lib "p2mpi01" (ByVal hostName As String, ByVal bufferlength As Integer) As Integer
 
Share this answer
 
v2
Comments
Toniyo Jackson 31-Mar-11 9:46am    
Use pre tag for code
Dave Kreskowiak 31-Mar-11 12:36pm    
Try declaring hostName ByRef instead of ByVal. Then change bufferlength to the length of the string you assigned to hostName before you make the call. hostName should be large enough to hold the results returned.

You may also want to change the type of hostName from String to StringBuilder.
Member 7743805 31-Mar-11 13:03pm    
That got me a little bit further. Changing to StringBuilder didn't work. I changed it to be ByRef and now I get a result of -3 which means if buffer is too small to hold return info. In this case, rtnInfoLength contains the buffer size needed, and returnInfo contains an empty string.

The rtnInfoLenght contains 29 in this instance. If I change buffer size to 29 I get the error

Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

If I change to anything less than 29 it returns a -3.


I'm not sure what you mean by HostName should be large enough to hold the results. If it's a string should it not be unlimited? Also not sure what you mean by change bufferlength to the length of HostName. Do you mean take bufferlength = len(hostname)?


Thanks again for the help.
I assume you tried googling your problem before asking the question here. Anyway, incase not, try this[^] if it works for you. It gives you instructions on tweaking some settings on your VS. If not, then you can try this[^].
 
Share this answer
 
Comments
Member 7743805 31-Mar-11 9:55am    
Yes I googled it but everything I have tried hasn't worked.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900