Hi, I get "first-chance exception at 0x1000161f in myapp.exe: 0c0000005: Access violation reading location 0x00000000."

If i execute the WFSOpen command. To be able to receive the error pointing to the correct error value I've done this:

LPHSERVICE lphService;
lphService = 0; // I put 0 because the EXIT_SUCCESS is also 0
HRESULT hResult;
WFSVERSION SvcVersion, SpiVersion;
char szLogicalName[]="Epson1200";
hResult = (WFSOpen(szLogicalName,WFS_DEFAULT_HAPP,"Epson Print",WFS_TRACE_NONE,TWO_MINUTES,RECOGNISED_VERSIONS,&SvcVersion,&SpiVersion,lphService));

if(hResult == WFS_ERR_CANCELED)
cout << WFS_ERR_CANCELED << endl; // This returns -4
}else if(hResult == WFS_ERR_SERVICE_NOT_FOUND)
cout << WFS_ERR_SERVICE_NOT_FOUND << endl; // This is -43
}else if(hResult == WFS_ERR_CONNECTION_LOST)
cout << WFS_ERR_CONNECTION_LOST << endl; // -54
}else if(hResult == WFS_ERR_INTERNAL_ERROR)
cout << WFS_ERR_INTERNAL_ERROR << endl; // -15
}else if(hResult == WFS_ERR_INVALID_APP_HANDLE)
cout << WFS_ERR_INVALID_APP_HANDLE << endl; // -17
}else if(hResult == WFS_ERR_INVALID_POINTER)
cout << WFS_ERR_INVALID_POINTER << endl; // This is the error I get which is -26

I get the (-26) which says "A pointer parameter does not point to accessible memory when you refer to the cen documentation.

Any one know which pointer is refered to by this error here?


11 Months
Discussion Span
Last Post by Mr.M

The error is saying that you are trying to access a NULL value, which results in a segfault. You need to determine which variable/argument has a null value.


Your lphService variable is defined as a null pointer so it's not possible to return a handle for the service in the call to WFSOpen(...)
Either allocate memory dynamically for lphService or change the definition to:

hResult = (WFSOpen(szLogicalName,WFS_DEFAULT_HAPP,"Epson Print",WFS_TRACE_NONE,TWO_MINUTES,RECOGNISED_VERSIONS,&SvcVersion,&SpiVersion,&hService));

@nullptr I tried that but I got this error error C2664: 'WFSOpen' :cannot convert parameter 9 from 'HSERVICE' to 'LPHSERVICE'

What I think I will have to clear out is that the code on my first post is written outside the

BOOL    Wfs_Open(LPHSERVICE lphService)


block because I'm using the console and I wanted to display the error because I failed to map the messages, so the code on the first post is called as is under the

cout << "Started service" << endl;
cout << "Opening a session" << endl;
// The code on the first post here
// as well as all the checkings of all functions
// if they fail which is
// fSuccess=EXIT_FAILURE;

So I'm not sure wherther the problem is because this call is called outside the Wfs_Open() function or.


If anyone could tell me what's really am I missing here, because even if I do as per the guide, I still get the same error. Please guys help me out here.


In my experience that kind of error results from using an uninitialized pointer. A pointer variable contains the address of what you want to operate on. If it is uninitialized it has the value zero. Trying to access .ocation zero results in an error. ake sure all your pointer variables point at something valid.


Thanks. I think I see where's the problem but I don't know how I can solve this. The problem I think is within my hService is there another better way to write this function other then this?


@nullptr you are correct indeed, as the error state 'invalid pointer' (-26) error and these posts support this: http://www.dev-hq.net/c++/19--dynamically-allocating-memory, http://www.cplusplus.com/doc/tutorial/dynamic/, http://www.tutorialspoint.com/cplusplus/cpp_dynamic_memory.htm

@jim also your first post support this and its the post which enlighten me on this. Also @jim I meant that variable that should return the handle.

Now my problem is how can I apply the memory allocation in my case. Also will I have to keep doing memory allocation for each function or only for Wfs_Open()?


Now its gives me Unhandled exception at 0x00041910 in T.exe 0xC0000005: Access violation reading location 0x0000001e with options Break, Continue. I have added this:

 HRESULT hResult;
 hResult = WFS_SUCCESS;
 lphService = NULL;

The same error is still printed on screen.
It also sometime point to lphService=(LPHSERVICE)(lpResult->lpBuffer) and say NullReferenceException was not handled, object reference not set to an instance of an object.

I'm trying all my best to make this work, yes I'm not a C++ dev.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.