1. Henry Guo
  2. PowerBuilder
  3. Friday, 26 April 2024 14:43 PM UTC

I migrated our client's application from PowerBuilder 2017 32-bit to PowerBuilder 2022 64-bit, the below code are under Local External Functions declaration in a user object, the below code can successfully run in PowerBuilder 2017 32-bit, but after I migrated to PowerBuilder 2022 64-bit, it causes error when call the below external functions in the code, what should be changed for the below code?

Thanks for your helps!

 

// WSOCK32.DLL

FUNCTION int accept (int s, REF str_SockAddr addr, REF int addrlen) LIBRARY "WSOCK32.DLL" alias for "accept;Ansi"
FUNCTION int bind (int s, REF str_SockAddr addr, int addrlen) LIBRARY "WSOCK32.DLL" alias for "bind;Ansi"
FUNCTION int closesocket (int s) LIBRARY "WSOCK32.DLL"
FUNCTION int connect_alias (int s, REF str_SockAddr addr, int ilength) LIBRARY "WSOCK32.DLL" alias for "connect;Ansi"
FUNCTION int ioctlsocket (int s, long cmd, REF long arg) LIBRARY "WSOCK32.DLL"


FUNCTION int getpeername (int s, REF str_SockAddr addr , REF int addrlen) LIBRARY "WSOCK32.DLL" alias for "getpeername;Ansi"
FUNCTION int getsockname (int s, REF str_SockAddr addr, REF int addrlen) LIBRARY "\WSOCK32.DLL" alias for "getsockname;Ansi"
FUNCTION int getsockopt (int s, int level, int optname , REF char optval, REF int optlen) LIBRARY "WSOCK32.DLL" alias for "getsockopt;Ansi"
FUNCTION long htonl (long hostlong) LIBRARY "WSOCK32.DLL"
FUNCTION int htons (int hostshort) LIBRARY "WSOCK32.DLL"


FUNCTION long inet_addr (string cp) LIBRARY "WSOCK32.DLL" alias for "inet_addr;Ansi"
FUNCTION long inet_ntoa (long in ) LIBRARY "WSOCK32.DLL"
FUNCTION int listen (int s, int backlog) LIBRARY "WSOCK32.DLL"
FUNCTION long ntohl (long netlong) LIBRARY "WSOCK32.DLL"
FUNCTION int ntohs (int netshort) LIBRARY "WSOCK32.DLL"


FUNCTION int recv (int s, REF string buf , int buflen, int flags) LIBRARY "WSOCK32.DLL" alias for "recv;Ansi"
FUNCTION int recvfrom (int s, string buf , int buflen, int flags, REF str_SockAddr fromsocket , REF int fromlen) LIBRARY "WSOCK32.DLL" alias for "recvfrom;Ansi"
FUNCTION int select_alias (int w, REF fd_set readfds, REF fd_set writefds, REF fd_set exceptfds, REF timeval timeout) LIBRARY "FTPNETVC.DLL" alias for "select_alias;Ansi"
FUNCTION int send (int s, string msg, int msglen, int flags) LIBRARY "WSOCK32.DLL" alias for "send;Ansi"
FUNCTION int sendto (int s, string msg, int msglen, int flags, REF str_SockAddr addr, int addrlen) LIBRARY "WSOCK32.DLL" alias for "sendto;Ansi"


//FUNCTION int setsockopt (int s, int level, int optname, REF int optval, int optlen) LIBRARY "WSOCK32.DLL"
FUNCTION int shutdown (int s, int how) LIBRARY "WSOCK32.DLL"
FUNCTION int socket (int domain, int domaintype, int protocol) LIBRARY "WSOCK32.DLL"

// Database Functions

FUNCTION long gethostbyaddr(REF string addr, int addrlen, int addrtype) LIBRARY "WSOCK32.DLL" alias for "gethostbyaddr;Ansi"
FUNCTION long gethostbyname(Ref string host) LIBRARY "WSOCK32.DLL" alias for "gethostbyname;Ansi"
FUNCTION int gethostname(REF string host, int hostlen) LIBRARY "WSOCK32.DLL" alias for "gethostname;Ansi"
FUNCTION long getservbyport(int port, REF string proto) LIBRARY "WSOCK32.DLL" alias for "getservbyport;Ansi"
FUNCTION long getservbyname(REF string service, REF string proto) LIBRARY "WSOCK32.DLL" alias for "getservbyname;Ansi"

FUNCTION long getprotobynumber(int proto) LIBRARY "WSOCK32.DLL"
FUNCTION long getprotobyname(REF string proto) LIBRARY "WSOCK32.DLL" alias for "getprotobyname;Ansi"

// Microsoft Windows Extensions

FUNCTION int WSAStartup(int wVersionRequired, REF str_WSAData lpstr_WSAData) LIBRARY "WSOCK32.DLL" alias for "WSAStartup;Ansi"
FUNCTION int WSACleanup() LIBRARY "WSOCK32.DLL"
SUBROUTINE WSASetLastError(int iError) LIBRARY "WSOCK32.DLL"
FUNCTION int WSAGetLastError() LIBRARY "WSOCK32.DLL"
FUNCTION int WSAIsBlocking() LIBRARY "WSOCK32.DLL"

FUNCTION int WSAUnhookBlockingHook() LIBRARY "WSOCK32.DLL"
FUNCTION long WSASetBlockingHook() LIBRARY "WSOCK32.DLL"
FUNCTION int WSACancelBlockingCall() LIBRARY "CWINSOCK.DLL"
FUNCTION int WSAAsyncGetServByName(uint hWnd, uint msg, REF string aName, REF string proto, REF string buf, int buflen) LIBRARY "WSOCK32.DLL" alias for "WSAAsyncGetServByName;Ansi"
FUNCTION int WSAAsyncGetServByPort(uint hWnd, uint wMsg, int port, string proto, REF string buf, int buflen) LIBRARY "WSOCK32.DLL" alias for "WSAAsyncGetServByPort;Ansi"

FUNCTION int WSAAsyncGetProtoByName(uint hWnd, uint wMsg, REF string aName, REF string buf, int buflen) LIBRARY "WSOCK32.DLL" alias for "WSAAsyncGetProtoByName;Ansi"
FUNCTION int WSAAsyncGetProtoByNumber( uint hWnd, uint wMsg, int aNumber, REF string buf, int buflen) LIBRARY "WSOCK32.DLL" alias for "WSAAsyncGetProtoByNumber;Ansi"
FUNCTION int WSAAsyncGetHostByName(uint hWnd, uint wMsg, REF string aName, REF string buf, int buflen) LIBRARY "WSOCK32.DLL" alias for "WSAAsyncGetHostByName;Ansi"
FUNCTION int WSAAsyncGetHostByAddr(uint hWnd, uint wMsg, REF string addr, int addrlen, int addrtype, REF string buf, int buflen) LIBRARY "WSOCK32.DLL" alias for "WSAAsyncGetHostByAddr;Ansi"
FUNCTION int WSACancelAsyncRequest(uint hAsyncTaskHandle) LIBRARY "WSOCK32.DLL"

FUNCTION int WSAAsyncSelect(int s, uint hWnd, uint wMsg, long lEvent) LIBRARY "WSOCK32.DLL"

// NMPCIP.DLL

FUNCTION long dllVer() LIBRARY "NMPCIP.DLL"

// FTPNET.DLL

//FUNCTION long BeeperFTPNET(int nOpCode) LIBRARY "FTPNETVC.DLL"
//FUNCTION long ResolveAddressFromName(REF str_SockAddr sa_in, long he) LIBRARY "FTPNETVC.DLL"

// kernal

SUBROUTINE CopyStrMemory(REF str_hostent l_dest, long l_source, long l_cbcopy) LIBRARY "kernel32" alias for "RtlMoveMemory;Ansi"
SUBROUTINE CopyMemory(REF long l_dest, long l_source, long l_cbcopy) LIBRARY "kernel32" alias for "RtlMoveMemory"
SUBROUTINE hmemcpy(REF long l_dest, long l_source, long l_cbcopy) LIBRARY "kernel32"
SUBROUTINE StrCpy(REF string l_dest, long l_source) LIBRARY "kernel32" alias for "StrCpy;Ansi"
SUBROUTINE waitmessage() LIBRARY "kernel"
FUNCTION integer GetPrivateProfileString(REF string appname, REF string keyname, REF string default, REF string returnedstring, integer size, REF string filename) LIBRARY "kernel" alias for "GetPrivateProfileString;Ansi"
FUNCTION integer WritePrivateProfileString(REF string appname, REF string keyname, REF string newstring, REF string filename) LIBRARY "kernel" alias for "WritePrivateProfileString;Ansi"
FUNCTION boolean DestroyWindow(int w_handle) LIBRARY "kernel"

FUNCTION long GetFreeSpace(int w_handle) LIBRARY "kernel"
FUNCTION int GetFreeSystemResources(int SysResource) LIBRARY "kernel"
FUNCTION long GlobalCompact(long MinFree) LIBRARY "kernel"

 

John Fauss Accepted Answer Pending Moderation
  1. Saturday, 27 April 2024 21:00 PM UTC
  2. PowerBuilder
  3. # 1

Hi, Henry -

I encourage you to learn more about 64-bit application development using PowerBuilder. Appeon has made available an excellent publication about migrating 32-bit apps to 64-bit:

    https://docs.appeon.com/pb2022r3/migrating_32bit_applications_to_64bit/index.html

There is also a four-part series of tech articles on how to interface PB apps with the Windows API that you might find helpful. Here is a link to the first part:

    https://community.appeon.com/index.php/articles-blogs/tutorials-articles/2-powerbuilder/302-interfacing-pb-applications-with-the-windows-api-part-1

Best regards, John

Comment
There are no comments made yet.
Roland Smith Accepted Answer Pending Moderation
  1. Friday, 26 April 2024 16:57 PM UTC
  2. PowerBuilder
  3. # 2

Download my Winsock example here:

https://www.topwizprogramming.com/freecode_winsock.html

The zip file has PB 10.5 and 12.6 versions. Open the 12.6 version in PB 2022.

Comment
There are no comments made yet.
David Peace Accepted Answer Pending Moderation
  1. Friday, 26 April 2024 16:06 PM UTC
  2. PowerBuilder
  3. # 3

Hi

Normally a MS windows core 32 bit DLL will have an equivilant 64 Bit dll and windows just sorts this out for you with no code changes. However, I suspect that the WSOCK32.DLL does not exist as a 64-bit specific library, but the network operations it used to handle have been transitioned to newer libraries that are compatible with 64-bit systems.

I'm not an expert on this, but with a bit searching I found mentioned that Windows moved these functions to a DLL called WS2_32.dll. Perhaps it is possible that you need to use this DLL now in order to have the 64 bit functionality.

I hope that is a pointer in the right direction, but you will need to find a 64 bit DLL to perform the same functions and refactor the code.

Regards

David

 Info from Chat GPT:

WSOCK32.DLL is a system file in Windows used for handling network-related functions. Historically, it has been a 32-bit DLL (Dynamic Link Library) because it dates back to older versions of Windows designed for 32-bit architectures.

For modern versions of Windows that support 64-bit systems, including Windows 10 and later, there's a transition to 64-bit computing. Most system files, including networking libraries, have corresponding 64-bit versions to support 64-bit applications and system components.

In the case of networking libraries, the 64-bit equivalent of WSOCK32.DLL is typically found in the system's SysWOW64 directory, which contains 32-bit system files for compatibility. The actual 64-bit networking libraries are located in the System32 directory on 64-bit Windows systems.

Therefore, while the specific DLL named WSOCK32.DLL remains a 32-bit file for backward compatibility, modern Windows operating systems use other 64-bit networking libraries to handle networking functions in 64-bit applications. These files are not directly named as WSOCK32.DLL but serve the same purpose in 64-bit computing.

Comment
  1. Roland Smith
  2. Friday, 26 April 2024 16:59 PM UTC
Windows automatically loads the correct bitness DLLs. They are named the same and stored in different folders.
  1. Helpful 1
  1. Roland Smith
  2. Friday, 26 April 2024 17:00 PM UTC
The correct file is ws2_32.dll.
  1. Helpful 3
There are no comments made yet.
Chris Pollach @Appeon Accepted Answer Pending Moderation
  1. Friday, 26 April 2024 15:14 PM UTC
  2. PowerBuilder
  3. # 4

Hi Henry;

  The 64 bit errors are not surprising as at a quick glance ...

  • Window handles are now the LongPTR data type
  • You need 3rd party DLLs to be in 64 bit format
  • You should not be using ANSI as PB is Unicode.
  • etc ...

FYI:  https://docs.appeon.com/pb2022/migrating_32bit_applications_to_64bit/index.html

HTH

Regards .. Chris

Comment
  1. Henry Guo
  2. Friday, 26 April 2024 16:55 PM UTC
Thanks Chris!



Window handles are now the LongPTR data type --- Should I change all the int, long, uint datatype in my code to LongPTR datatype?



You should not be using ANSI as PB is Unicode --- How to replace ANSI with Unicode? Could you please give a sample for using Unicode?
  1. Helpful
  1. Chris Pollach @Appeon
  2. Friday, 26 April 2024 17:24 PM UTC
Handles: Any old reference to a Window "handle" that was declared as Long / uLong should now be LongPtr.

Unicode: ...

1: Remove the ANSI declaration in your external function declarations.

However, you will need a Unicode version of the WinSock DLL from the vendor

Currently, your WinSock declarations look like old ANSI based PB implementation (before PB v10).



2) For Windows SDK calls, there are UNicode equivalents. For example FindWindow ...

FUNCTION uLong FindWindow ( ref String classname, ref string windowname ) Library "USER32.DLL" ALIAS FOR "FindWindowA" // OLD

FUNCTION LongPTR FindWindow ( ref String classname, ref string windowname ) Library "USER32.DLL" ALIAS FOR "FindWindowW" // New



FYI: Use MSN for SDK declarations & use ...

https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-findwindowa // old (Ansi)

https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-findwindoww // New (Unicode)



HTH

Regards .. Chris
  1. Helpful 2
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.