fbpx
Welcome, Guest
Username: Password: Remember me
Welcome to the XSharp forum!

Tell us and our members who you are, what you like and why you became a member of this site.
We welcome all new members and hope to see you around a lot!
  • Page:
  • 1

TOPIC:

Structures 02 Jun 2021 11:22 #18707

  • antonello.negrone


  • Posts: 12
  • Hi,
    I'm running a new try to convert S.P.E. from VO to X#.
    I get successful compilation of the first DLL but it crashes at the very beginning of execution when allocating the connetion structure.

    Structures decl:
    VOSTRUCT SpeConnection
    	MEMBER	__uServer		AS PSZ
    	MEMBER	__sUserName		AS PSZ
    	MEMBER	__sPassword		AS PSZ
    	MEMBER  __nSpeUserPort	AS WORD
    	MEMBER  __nSpeTcpPort	AS WORD
    	MEMBER nTimeOut			AS DWORD
    	MEMBER dwFlags				AS DWORD
    	MEMBER oCSocket			IS speSocket
    
    VOSTRUCT speSocket
    	MEMBER handle		AS DWORD
    	MEMBER nLastError	AS LONG
    	MEMBER hConn		AS SpeConnection
    	MEMBER nRecvSpeed	AS LONG
    

    Global variable containing the current connection handle:
    GLOBAL hCurrentSpeConnection AS SpeConnection

    Allocating the memory for the struct:
    	hCurrentSpeConnection	:=	MemAlloc(_SizeOf(SpeConnection)) 

    Debugging the above line, the var hCurrentSpeConnection is NULL,


    but if I put MemAlloc to a generic PTR var, it gets a valid pointer.

    Is this a not yet supported feature or am I mistaking something?

    Thanks
    Antonello

    Please Log in or Create an account to join the conversation.

    Structures 02 Jun 2021 16:41 #18708

    • Chris
    • Chris's Avatar


  • Posts: 2566
  • HI Antonello,

    This should be working fine. Could it be you also have a local with the same name, or an Ivar?
    Can you create a full sample reproducing this and send it to have a look?

    I tried to simply copy/paste your code and run it and it is working well here, so there is probably something else getting in the way. Btw, you are using the latest X# 2.8a build, is that right?
    XSharp Development Team
    chris(at)xsharp.eu

    Please Log in or Create an account to join the conversation.

    Structures 02 Jun 2021 18:32 #18709

    • antonello.negrone


  • Posts: 12
  • Chris,

    declaring a local variable with a different name it works. Thanks!

    Now I reached a new stop when calling the WinAPI socket() func, which returns always INVALID_SOCKET:
    oSelf.oCSocket.handle	:=	socket(PF_INET, SOCK_STREAM, 0)

    From your experience this approach is allowed by the CLR?

    Maybe is it better to redesign the lib in a native .Net way?

    Please Log in or Create an account to join the conversation.

    Structures 02 Jun 2021 18:52 #18710

    • Chris
    • Chris's Avatar


  • Posts: 2566
  • Hi Antonello,

    In 99% of the cases, if something is working in VO, then it should also work in X#. Otherwise it is a bug that we need to look into, or it is something from the 1% that is not supported in X#. I am not familiar myself with sockets programming, but I see no reason why it should not work in X#. I tried a simple call to socket(PF_INET, SOCK_STREAM, 0) and it returns INVALID_SOCKET also in VO, so I assume there's something additional needed. Can you prepare a sample that works in VO but not in X# to have a look at?

    Regarding redesigning the library to use .Net classes instead, this is generally the best option, but of course it also depends on factors like how much code you would need to rewrite and how much time you are prepared to spend on this, if everything you need is indeed supported in plain .Net and not only via Win32 API etc... Only you can decide this!
    XSharp Development Team
    chris(at)xsharp.eu

    Please Log in or Create an account to join the conversation.

    Structures 02 Jun 2021 23:23 #18711

    • antonello.negrone


  • Posts: 12
  • Chris, you are right (of course :)) !

    Preparing a sample-code is a bit tricky for me now, but with some hint from you I think we can reach a the goal!

    And I found that the issue is a not-called WsaStartup() inside a
    PROCEDURE InitSpeClient() _INIT2

    Searching the kb I have not found yet anything about _INIT1, _INIT2 ecc in X#. Are they supported?

    About the redesign I think it will be a must-have for the future, but a working conversion from VO will give me the time to plan it and, meanwhile, begin the conversion work on my major application.

    Thanks

    Please Log in or Create an account to join the conversation.

    Structures 02 Jun 2021 23:26 #18712

    • Chris
    • Chris's Avatar


  • Posts: 2566
  • Hi Antonello,

    Yes, _INIT procedures are fully supported and should be working exactly the same way as in VO. Again, that is unless there's some still unfound bug :)
    XSharp Development Team
    chris(at)xsharp.eu

    Please Log in or Create an account to join the conversation.

    Structures 02 Jun 2021 23:30 #18713

    • robert
    • robert's Avatar


  • Posts: 2222
  • Antonello

    antonello.negrone wrote: Chris,

    oSelf.oCSocket.handle	:=	socket(PF_INET, SOCK_STREAM, 0)


    Should that not be
    oSelf.oCSocket.handle	:=	socket(AF_INET, SOCK_STREAM, 0)

    (AF_INET instead of PF_INET)

    Robert
    XSharp Development Team
    The Netherlands

    Please Log in or Create an account to join the conversation.

    Last edit: by robert.

    Structures 03 Jun 2021 13:51 #18714

    • antonello.negrone


  • Posts: 12
  • Chris,

    also this issue is fixed: the application was not declared in VO dialect.

    Thanks
    Antonello

    Please Log in or Create an account to join the conversation.

    Structures 03 Jun 2021 13:54 #18715

    • antonello.negrone


  • Posts: 12
  • Thanks for the advice Robert!

    Since the const value is the same (2), the "bug" was never discovered and is very old :lol:

    Please Log in or Create an account to join the conversation.

    • Page:
    • 1