Structures

We encourage new members to introduce themselves here. Get to know one another and share your interests.
Post Reply
antonello.negrone
Posts: 22
Joined: Tue May 03, 2016 8:57 am
Location: Italy

Structures

Post by antonello.negrone »

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:

Code: Select all

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:

Code: Select all

GLOBAL hCurrentSpeConnection AS SpeConnection
Allocating the memory for the struct:

Code: Select all

	hCurrentSpeConnection	:=	MemAlloc(_SizeOf(SpeConnection)) 
Debugging the above line, the var hCurrentSpeConnection is NULL,
Image

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
User avatar
Chris
Posts: 4599
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

Structures

Post by Chris »

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?
Chris Pyrgas

XSharp Development Team test
chris(at)xsharp.eu
antonello.negrone
Posts: 22
Joined: Tue May 03, 2016 8:57 am
Location: Italy

Structures

Post by antonello.negrone »

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:

Code: Select all

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?
User avatar
Chris
Posts: 4599
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

Structures

Post by Chris »

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!
Chris Pyrgas

XSharp Development Team test
chris(at)xsharp.eu
antonello.negrone
Posts: 22
Joined: Tue May 03, 2016 8:57 am
Location: Italy

Structures

Post by antonello.negrone »

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

Code: Select all

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
User avatar
Chris
Posts: 4599
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

Structures

Post by Chris »

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 :)
Chris Pyrgas

XSharp Development Team test
chris(at)xsharp.eu
User avatar
robert
Posts: 4292
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

Structures

Post by robert »

Antonello
antonello.negrone wrote:Chris,

Code: Select all

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

Code: Select all

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

Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
antonello.negrone
Posts: 22
Joined: Tue May 03, 2016 8:57 am
Location: Italy

Structures

Post by antonello.negrone »

Chris,

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

Thanks
Antonello
antonello.negrone
Posts: 22
Joined: Tue May 03, 2016 8:57 am
Location: Italy

Structures

Post by antonello.negrone »

Thanks for the advice Robert!

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