Newbie needs help with VC++ DLL 
Author Message
 Newbie needs help with VC++ DLL

I am trying to write a simple VC6++ DLL for hooking use by a VB6 app. I have
successfully created a DLL passing numeric data, but when I attempt any
basic string manipulation (e.g. lstrcat(mystring, "XYZ")), my VB app GPFs
every time. Severe loss of hair has resulted!

Am I failing to include the necessary header files or allocate memory? What
data types - LPSTR/LPTSTR - Unicode or ANSI?

Could a VC++ expert point me at a simple DLL that illustrates string
manipulation.

Many thanks,

John Way



Fri, 10 May 2002 03:00:00 GMT  
 Newbie needs help with VC++ DLL
John,

At the C++ end:

extern "C" long WINAPI StringOp(LPSTR lpszString, long nSize)
{
    CString        csTest = "Hello world";

    if (csTest.GetLength() <= nSize)
        strcpy(lpszString, (LPCSTR) csTest);

    return csTest.GetLength();

Quote:
}

Ensure StringOp is entered under the Declares section of the .def file.

VB end:

declare function StringOp lib "MyDll.dll"(byval lpszString$, byval nSize&)
as long

VB usage:

    dim StrRet$
    dim nRet&

    StrRet$ = space$(100)
    nRet& = StringOp(StrRet$, len(StrRet$))
    if nRet& > len(StrRet$) then
        StrRet$ = space$(nRet&+1)
        nRet& = StringOp(StrRet$, len(StrRet$))
    end if
    StrRet$ = left$(StrRet$, nRet&)

Note that the string pointer is declared ByVal even though it is a pointer.
This is a language "feature" you just have to get used to <g>.  Apparently
it instructs VB to convert the BSTR (which is what VB stores strings as) to
a LPSTR.

BTW untested code, so I hope not too many typos!

HTH

Peter Beach


Quote:
> I am trying to write a simple VC6++ DLL for hooking use by a VB6 app. I
have
> successfully created a DLL passing numeric data, but when I attempt any
> basic string manipulation (e.g. lstrcat(mystring, "XYZ")), my VB app GPFs
> every time. Severe loss of hair has resulted!

> Am I failing to include the necessary header files or allocate memory?
What
> data types - LPSTR/LPTSTR - Unicode or ANSI?

> Could a VC++ expert point me at a simple DLL that illustrates string
> manipulation.

> Many thanks,

> John Way



Fri, 10 May 2002 03:00:00 GMT  
 Newbie needs help with VC++ DLL

As Peter Beach points out, you have to pass the string ByVal although you
have a pointer as argument in your C or C++ function. Note that you can't
pass the content of a text-box directly (e.g ok=dosomething(txtText.Text)),
you have to copy it to a string first. I did some small stuff in that way
and it works fine. Seems that passing string-arrays is a far more hairy
thing (no advice for this, as I'm no expert...).


Quote:
> I am trying to write a simple VC6++ DLL for hooking use by a VB6 app. I
have
> successfully created a DLL passing numeric data, but when I attempt any
> basic string manipulation (e.g. lstrcat(mystring, "XYZ")), my VB app GPFs
> every time. Severe loss of hair has resulted!

> Am I failing to include the necessary header files or allocate memory?
What
> data types - LPSTR/LPTSTR - Unicode or ANSI?

> Could a VC++ expert point me at a simple DLL that illustrates string
> manipulation.

> Many thanks,

> John Way



Fri, 10 May 2002 03:00:00 GMT  
 Newbie needs help with VC++ DLL
Many thanks, I'm on my way again!


Quote:

> As Peter Beach points out, you have to pass the string ByVal although you
> have a pointer as argument in your C or C++ function. Note that you can't
> pass the content of a text-box directly (e.g

ok=dosomething(txtText.Text)),
Quote:
> you have to copy it to a string first. I did some small stuff in that way
> and it works fine. Seems that passing string-arrays is a far more hairy
> thing (no advice for this, as I'm no expert...).



> > I am trying to write a simple VC6++ DLL for hooking use by a VB6 app. I
> have
> > successfully created a DLL passing numeric data, but when I attempt any
> > basic string manipulation (e.g. lstrcat(mystring, "XYZ")), my VB app
GPFs
> > every time. Severe loss of hair has resulted!

> > Am I failing to include the necessary header files or allocate memory?
> What
> > data types - LPSTR/LPTSTR - Unicode or ANSI?

> > Could a VC++ expert point me at a simple DLL that illustrates string
> > manipulation.

> > Many thanks,

> > John Way



Sat, 11 May 2002 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Need help passing a DC to a vc++ dll

2. Need help passing a DC handle from vb to a vc++ dll

3. Need help passing a DC to a vc++ dll

4. NEED help Calling a VC++ DLL from VB4

5. HELP NEEDED: VB3.0 vs VC/C++ 1.52 DLL

6. I need help from a vb and vc++ expert

7. I need help from a vb and vc++ expert

8. Newbie needs help in reading installed programs from the registry using RegObj.dll

9. Newbie needs help in reading installed programs from the registry using RegObj.dll

10. newbie needs help with calling a DLL

11. I need help on DLL's for a newbie

12. Newbie needs help in reading installed programs from the registry using RegObj.dll

 

 
Powered by phpBB® Forum Software