|
Well this one is needed as far as I knnow to store the adress you want to listen, f.ex.
<br />
SOCKADDR_IN lSockAddr;<br />
memset(&lSockAddr,0, sizeof(lSockAddr));<br />
lSockAddr.sin_family = AF_INET;<br />
lSockAddr.sin_port = htons(8500);<br />
lSockAddr.sin_addr.s_addr = INADDR_ANY;
and afterwards you can check if all initialize went OK with
<br />
if(lSockAddr.sin_addr.s_addr ==INADDR_NONE)<br />
|
|
|
|
|
Sorry. Maybe I wasn't clear about my problem. I'm not asking how to use the bind function or the sockaddr_in structure. I'm just curious why they are declared the way they are. i.e., why is the 'struct' keyword needed in the places I have in bold. It seems to me like it's not really necessary. I'm sure I'm wrong but I don't understand why.
|
|
|
|
|
Well the first "struct" is simply the parameter required when you pass the function. Secondly, it is not uncommon to have a structure that is contained in another structure, that is perfectly legal.
|
|
|
|
|
I appreciate your reponses guys but I think you're missing the point of my question. Let me rephrase it.
Observe the 2 following code snippets. Both are almost identical accept one uses the 'struct' keyword in the declaration and the other doesn't.
struct MyStruct
{};
void MyFunction (const MyStruct * pMyStruct)
{
return;
}
struct MyStruct
{};
void MyFunction (const struct MyStruct * pMyStruct)
{
return;
}
Despite these differences, both pieces of code compile.
So whats the point in using the 'struct' keyword at all?
Microsoft doesn't use it other functions when passing a struct or struct pointer to a function. So why do they do it in the socket function bind? Is it simply for clarification or is it more important than that?
|
|
|
|
|
It's a difference between C and C++.
In C, names declared with struct , union and enum are in a different namespace to the built-in types and typedef s. You have to use the appropriate keyword when you use it, otherwise you'll get an error.
It's very common for a struct declaration to be included within a typedef declaration so that the namespace is 'flat'. In theory you could declare a typedef with the same name as a struct , union or enum .
C++ does away with this: there is no separate struct , union or enum namespace. It's not an error to prefix a type name using struct , union or enum , (not sure about class ) but is no longer necessary. I think the compiler is supposed to check, if you do use the keyword, that the type is actually what you say it is (i.e. struct , union or enum ).
|
|
|
|
|
Thanks too you also Chris. Very thorough.
|
|
|
|
|
This use of the struct keyword is a relic from C where it is a part of the type name.
In C++ it's perfectly legal to omit the struct keyword.
E.g. for C
struct MyStruct
{
int nFirst;
int nSecond;
};
int main( int argc, char* argv[] )
{
struct MyStruct theStruct;
MyStruct theStructCopy;
}
and for C++
struct MyStruct
{
int nFirst;
int nSecond;
};
int main( int argc, char* argv[] )
{
struct MyStruct theStruct;
MyStruct theStructCopy;
}
--
Roger
"It's supposed to be hard, otherwise anybody could do it!" - selfquote
"No one remembers a coward!" - Jan Elfström 1998 "...but everyone remembers an idiot!" - my lawyer 2005 when heard of Jan's saying above
|
|
|
|
|
Makes perfect sense now. Thank you Roger.
|
|
|
|
|
The icons on the windows system menu are made from the true type font Marlett. Does anybody know how I can use these icons? Are they created from the font at runtime (how?), or are they allocated as icons in a ressource (which?).
MS
|
|
|
|
|
Neither-Nor
see MSDN: DrawFrameControl, if should be the DFCS_CAPTIONCLOSE, DFCS_CAPTIONMAX etc. uState values
Developers, Developers, Developers, Developers, Developers, Developers, Velopers, Develprs, Developers! We are a big screwed up dysfunctional psychotic happy family - some more screwed up, others more happy, but everybody's psychotic joint venture definition of CP Linkify!|Fold With Us!
|
|
|
|
|
Thanks, thats seems to be the solution.
MS
|
|
|
|
|
Hi
I want application to convert unicode enabled. so for this i am converting all datatype to wide characters.if i used only widecharacter datatypes then Is they applicable for both unicode and ASCII.
|
|
|
|
|
I suspect you want TCHAR.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
The wchar_t type can be used by both ANSI and Unicode applications, just like int and double can be.
But what exactly do you mean by "Unicode enabled"? Do you mean that you want the application to support Unicode text, but still run on ANSI-only systems like Win 9x/me, or you want to write a native Unicode application, that only uses the Unicode APIs, and not the ANSI ones?
Any application, regardless of an ANSI or a Unicode build, can manipulate both Unicode and ANSI data, and can even make calls to both versions of API functions. For example:
MessageBoxA( NULL, "ANSI", "MessageBox", MB_OK );
<code>MessageBoxW( NULL, L"Unicode", L"MessageBox", MB_OK );</code> When developers talk about a Unicode application, they generally mean a Unicode build of the application, which means that it is linked against the Unicode Windows API libraries, and will not run an an ANSI-only system.
There is no such thing as a TCHAR application. There is TCHAR-based code can be used to create both both ANSI and Unicode builds. TCHAR and TCHAR-based identifiers/names like _tcscpy(...) get converted to the character type for the build being done.
For example, for an ANSI build, TCHAR becomes char , _tcscpy(...) becomes strcpy(...) and MessageBox(...) becomes MessageBoxA(...) .
For a Unicode build, TCHAR becomes wchar_t , _tcscpy(...) becomes wcscpy(...) and MessageBox(...) becomes MessageBoxW(...) .
Peace!
-=- James If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! DeleteFXPFiles & CheckFavorites (Please rate this post!)
|
|
|
|
|
Hi all,
I have a C function in my dll workspace. This function is exported from the dll. I want to return value from the function. The value is of enum type. The declaration and the defination of this enum type variable is in some different .h file. so how should i export this function and get the return value.
I have exported the function by using the following statement.
__declspec(dllexport) rs_result rdiff_sig(const char *BasisPath, const char *SigPath);
i am getting error messages and they are :
error C2146: syntax error : missing ';' before identifier 'rdiff_sig'
error C2501: 'rs_result' : missing storage-class or type specifiers
fatal error C1004: unexpected end of file found
How should i solve this issue.
Please help me.
Thanks
Datta
|
|
|
|
|
If you return an enum, the program using the dll needs to know what it is, so you need to include the header file containing the declaration of the enum in your program also.
|
|
|
|
|
Yes i included the .h file and it worked.
Thanks
|
|
|
|
|
Hi all,
I have a win32 dll workspace. In this workspace i have most of the files as .c files. I want to export one of the function from this dll. The function is a static function. so for that function if i export it in this way
__declspec(dllexport) static rdiff_sig(const char *BasisPath, const char *SigPath);
i am getting one error message as below.
error C2201: 'rdiff_sig' : must have external linkage in order to be exported/imported
What should i do to solve this problem.
Thanks
Datta K.
|
|
|
|
|
I'm not an expert in C programming but I think that declaring a global function as static means that it is only accessible from within that file. Did you try what your compiler told you ? That is specify the function as extern (put the keyword extern in front of it) ?
|
|
|
|
|
I want the caption bar buttons(i.e,mim,max,and close) to be removed completely.Is it possible.
|
|
|
|
|
remove them from the system menu of your application...
|
|
|
|
|
Thanks.I have another question can we replace these by bitmap buttons with same features.Because i have added gradient color to the title bar and now look of these buttons is not good on the title bar.so only i want to remove these buttons.And i want to add bitmap buttons in their place.Is my approach good or can we modify look of existing buttons on the title bar.
|
|
|
|
|
|
Hi,
From a CPP program, I am creating a service. And from that service I am invoking an exe with CreateProcess function. The problem here is that, when that service is started locally then the exe's GUI is visble. But if the service is started from the machine thru remotedesktop connection, the exe's GUI is not visible. But I can see the exe process in task manager.
Please help me in this regards.
Thanks in advance.
Surendran
|
|
|
|
|
Hi,
If it is a service, then it is executed in local session, which is different from the one that you're operating.
You have to attach your service desktop to the one you're going to display GUI on. AFAIK, there's no way to attach your GUI to something like "global" desktop so it would be visible for all. Only one desktop can be attached at once.
I suggest, creating GUI as client app and use IPC to speak with your service. This way, your GUI may have access to the service from multiple desktops at once. use sockets, shared memory or pipes for IPC (shmem or pipe should be created in global namespace).
Regards
|
|
|
|