Re: How include header file?

2022-09-07 Thread Injeckt via Digitalmars-d-learn

On Wednesday, 7 September 2022 at 23:01:34 UTC, Mike Parker wrote:

On Wednesday, 7 September 2022 at 20:23:03 UTC, Injeckt wrote:


Convert it to D:

	extern(C) const(char)* inet_ntop(int af, const(void)* src, 
char* dst, socklen_t size);


Win32 API functions need to be `extern(Windows)`.



You probably also need:

alias socklen_t = ...;


https://github.com/dlang/dmd/blob/master/druntime/src/core/sys/windows/winsock2.d#L17

`alias socklen_t = int`




It doesn't work. "Reference to an unresolved external symbol 
_inet_ntop".


That's a linker error. You need to link with `ws2_32.lib`.


Thank you so much. Now It works!


Re: How include header file?

2022-09-07 Thread Injeckt via Digitalmars-d-learn

On Wednesday, 7 September 2022 at 22:57:53 UTC, Loara wrote:

On Wednesday, 7 September 2022 at 20:23:03 UTC, Injeckt wrote:
On Wednesday, 7 September 2022 at 19:38:52 UTC, H. S. Teoh 
wrote:
On Wed, Sep 07, 2022 at 06:11:14PM +, Injeckt via 
Digitalmars-d-learn wrote:




You need to link the DLL to your project. Which DLL contains 
the definiton of `inet_ntop`?


ws2_32.dll


Re: How include header file?

2022-09-07 Thread Mike Parker via Digitalmars-d-learn

On Wednesday, 7 September 2022 at 20:23:03 UTC, Injeckt wrote:


Convert it to D:

	extern(C) const(char)* inet_ntop(int af, const(void)* src, 
char* dst, socklen_t size);


Win32 API functions need to be `extern(Windows)`.



You probably also need:

alias socklen_t = ...;


https://github.com/dlang/dmd/blob/master/druntime/src/core/sys/windows/winsock2.d#L17

`alias socklen_t = int`




It doesn't work. "Reference to an unresolved external symbol 
_inet_ntop".


That's a linker error. You need to link with `ws2_32.lib`.


Re: How include header file?

2022-09-07 Thread Loara via Digitalmars-d-learn

On Wednesday, 7 September 2022 at 20:23:03 UTC, Injeckt wrote:
On Wednesday, 7 September 2022 at 19:38:52 UTC, H. S. Teoh 
wrote:
On Wed, Sep 07, 2022 at 06:11:14PM +, Injeckt via 
Digitalmars-d-learn wrote:
I need to include this Ws2tcpip.h header file to my project. 
How can I do this? It's all because I need inet_ntop function 
from this header file.


If that's the only function you need, you can just copy the 
declaration of inet_ntop into your .d file and mark it as 
extern(C). E.g., on my OS it's declared as:


	const char *inet_ntop(int af, const void *restrict src, char 
*restrict dst, socklen_t size);


Convert it to D:

	extern(C) const(char)* inet_ntop(int af, const(void)* src, 
char* dst, socklen_t size);


You probably also need:

alias socklen_t = ...;

The definition can be found in your system header files. 
Probably you can just get away with size_t.



T


It doesn't work. "Reference to an unresolved external symbol 
_inet_ntop". I guess I can add my utils.c to my .d project when 
I compile project and I need write in this file function 
wrapper of inet_ntop.


You need to link the DLL to your project. Which DLL contains the 
definiton of `inet_ntop`?


Re: How include header file?

2022-09-07 Thread Steven Schveighoffer via Digitalmars-d-learn

On 9/7/22 4:23 PM, Injeckt wrote:

On Wednesday, 7 September 2022 at 19:38:52 UTC, H. S. Teoh wrote:
On Wed, Sep 07, 2022 at 06:11:14PM +, Injeckt via 
Digitalmars-d-learn wrote:
I need to include this Ws2tcpip.h header file to my project. How can 
I do this? It's all because I need inet_ntop function from this 
header file.


If that's the only function you need, you can just copy the 
declaration of inet_ntop into your .d file and mark it as extern(C). 
E.g., on my OS it's declared as:


const char *inet_ntop(int af, const void *restrict src, char 
*restrict dst, socklen_t size);


Convert it to D:

extern(C) const(char)* inet_ntop(int af, const(void)* src, char* 
dst, socklen_t size);


You probably also need:

alias socklen_t = ...;

The definition can be found in your system header files. Probably you 
can just get away with size_t.



T


It doesn't work. "Reference to an unresolved external symbol 
_inet_ntop". I guess I can add my utils.c to my .d project when I 
compile project and I need write in this file function wrapper of 
inet_ntop.


On windows, it might have different versions based on character width.

Don't have time right now to look it up on my windows system.

-Steve


Re: How include header file?

2022-09-07 Thread Injeckt via Digitalmars-d-learn

On Wednesday, 7 September 2022 at 20:23:03 UTC, Injeckt wrote:
_inet_ntop". I guess I can add my utils.c to my .d project when 
I compile project and I need write in this file function 
wrapper of inet_ntop.


No, it doesn't work. Jesus I need to figure out how to add 
WS2tcpip.h


Re: How include header file?

2022-09-07 Thread Injeckt via Digitalmars-d-learn

On Wednesday, 7 September 2022 at 19:38:52 UTC, H. S. Teoh wrote:
On Wed, Sep 07, 2022 at 06:11:14PM +, Injeckt via 
Digitalmars-d-learn wrote:
I need to include this Ws2tcpip.h header file to my project. 
How can I do this? It's all because I need inet_ntop function 
from this header file.


If that's the only function you need, you can just copy the 
declaration of inet_ntop into your .d file and mark it as 
extern(C). E.g., on my OS it's declared as:


	const char *inet_ntop(int af, const void *restrict src, char 
*restrict dst, socklen_t size);


Convert it to D:

	extern(C) const(char)* inet_ntop(int af, const(void)* src, 
char* dst, socklen_t size);


You probably also need:

alias socklen_t = ...;

The definition can be found in your system header files. 
Probably you can just get away with size_t.



T


It doesn't work. "Reference to an unresolved external symbol 
_inet_ntop". I guess I can add my utils.c to my .d project when I 
compile project and I need write in this file function wrapper of 
inet_ntop.


Re: How include header file?

2022-09-07 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Sep 07, 2022 at 06:11:14PM +, Injeckt via Digitalmars-d-learn wrote:
> I need to include this Ws2tcpip.h header file to my project. How can I
> do this? It's all because I need inet_ntop function from this header
> file.

If that's the only function you need, you can just copy the declaration
of inet_ntop into your .d file and mark it as extern(C). E.g., on my OS
it's declared as:

const char *inet_ntop(int af, const void *restrict src, char *restrict 
dst, socklen_t size);

Convert it to D:

extern(C) const(char)* inet_ntop(int af, const(void)* src, char* dst, 
socklen_t size);

You probably also need:

alias socklen_t = ...;

The definition can be found in your system header files. Probably you
can just get away with size_t.


T

-- 
The volume of a pizza of thickness a and radius z can be described by the 
following formula: pi zz a. -- Wouter Verhelst