Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

"Need superior Guru help with C DLL for VB"

Posted on 1999-01-24
2
Medium Priority
?
268 Views
Last Modified: 2010-05-03
"Need superior Guru help with C DLL for VB"

I need a guru to help me!

I have a C DLL that is being developed, however in VB I get the following
error with the following C interfaces to the DLL: (My VB Code is at the
bottom of this message)

What can be done so these errors don't occur in the VB IDE (or compiled as
pseudocode)?

I am using VB 5 and have no problems declaring or utilizing DLL's in general.



With the following code I get the following error when attempting to run the
corresponding VB code in the VB IDE (or compiled as p-code): "Run-Time error
49: Bad DLL Calling convention". NOTE: If I compile the VB Code down below to
n native code exe it appears to work correctly. (However, because this is not
good enough for me, since it won't work in the IDE, then something may be
declared incorrectly and memory errors might occur later on)

SOX1 (withOUT stdcall):
_declspec(dllexport) void __stdcall SOX(LPCSTR, LPCSTR, LPCSTR, LPCSTR,
LPCSTR);
LPCSTR            cmd,
LPCSTR            stdout_fl,
LPCSTR            out,
LPCSTR            stderr_fl,
LPCSTR            err)
void            SOX(
{...}

The following code produces the following error when executed in the VB IDE
(when run as p-code) or as a native code executable: "Run-Time Error 453:
Can't find entry point in sox2.dll"

SOX2 (WITH stdcall):
_declspec(dllexport) void SOX(LPCSTR, LPCSTR, LPCSTR, LPCSTR, LPCSTR);
void __stdcall      SOX(
LPCSTR            cmd,
LPCSTR            stdout_fl,
LPCSTR            out,
LPCSTR            stderr_fl,
LPCSTR            err)
{...}


Here is my VB Declaration:

'Test DLL1
Private Declare Sub SOX Lib "sox1.dll" (ByVal Cmd As String, ByVal
OutMessFile As String, ByVal OutMess As String,

'Test DLL2
'Private Declare Sub SOX Lib "sox2.dll" (ByVal Cmd As String, ByVal
OutMessFile As String, ByVal OutMess As String,
ByVal ErrMessFile As String, ByVal ErrMess As String)

Here is the VB Function that calls the DLL:
Function TestCode()
Dim a As String
Dim b As String
Dim c As String
Dim d As String
Dim e As String

a = txtIn.Text
b = "out.tmp"
c = String(513, " ")  'Create a buffer of 513
d = "err.tmp"
e = String(513, " ")  'Create a buffer of 513
 
SOX a, b, c, d, e

txtOut.Text = c
txtErr.Text = e
End Function
0
Comment
Question by:bre342
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 1

Expert Comment

by:muffinthedog
ID: 1470393
Sure it taint BSTR your passing then
LPSTR myString;
myString = (LPSTR)passedBSTR;

and are you using a DEF file?

0
 

Accepted Solution

by:
JimKarabatsos earned 320 total points
ID: 1470394
Umm, you do need to use stdcall, so we'll work with the sox2 dll.  The problem is that the C compiler is exporting the name in lower case.  I think you will find that you need to do one of two things:

1. tell the linker that you want to presrve case for exported symbols, or

2. use this declaration:

Private Declare Sub SOX Lib "sox2.dll" Alias "sox" _
  (ByVal Cmd As String, ByVal OutMessFile As String, _
   ByVal OutMess As String, ByVal ErrMessFile As String, _
   ByVal ErrMess As String)

-- Jim
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question