c++windowswinapicen-xfs

How do i write and call this type


I'm having a problem here and the problem is that the hService is 0

I'm having or creating the Windows Form application and I've put:

HSERVICE hService=0;
BOOL fSuccess=EXIT_SUCCESS;

if(Wfs_Startup())
{
     // This returns a successful startup even if I write something here 
     // to be displayed by a textbox it does. That means the Startup is ok.
     if(Wfs_Open(&hService))
     {
         // What ever I put here doesn't show on a textbox and the application jumps to
         // the exception of this block which means there's a problem here, at first I 
         // thought it was because of no corresponding logical name on a registry but what 
         // I found out was that if I check below the Startup block and check the hService 
         // it's 0 so it doesn't receive the correct data from the startup.
    }
}

so I took that from "I will say" a function that is written like this:

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdDLine, 
                                                                            int nShowCmd)
{
    //THE CODE BLOCK IS THE SAME AS THE ABOVE THAT GOES HERE.
}

So I took the inside code block to FormLoad but this is giving me the above mentioned problem, can I have both the FormLoad and the WinMain? Because I tried to have the WinMain but there was an error I think it said there can't be two Main or something like that. Also how can I call the WinMain within FormLoad as when I tried it required the arguments to be included and the main problem is that I can't add the arguments in a FormLoad.

any suggestion to how can I resolve this problem?

Sorry but don't know the easy way to explain this. But keep in mind the problem that the hService returns 0.

Ok just to simplify this question:

How to call this type of Function that's starts with HRESULT at the beginning please check above. What I want is to fire that Function, I think that will simplify this even though there's another question about calling it on FormLoad but first I want to know how to call/fire that kind of Function?

The problem is that the IDE says I can not have the int WinMain on Windows Form because its already has something like that but when I'm working with command its works. I can have WinMain and Main but can't have WinMain and FormLoad not inside but within the project or page. To understand please create a Windows Form App and try typing the int WinMain code you will see what's my problem here.


Solution

  • I have found the great tutorial that gives a good reason why I'm getting this problem:

    https://msdn.microsoft.com/en-us/library/bb384843.aspx