Click here to Skip to main content
       

C / C++ / MFC

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page  Show 
GeneralRe: Does anyone know this c plus plus knowledge?memberjschell16 Jan '13 - 9:10 
yu-jian wrote:
why the c plus plus allow defining a variable without name?

 
It isn't doing that.
 
You are confusing 'variable' with 'expession'.
 
In the following the left 'x' is a varible while the right side is an expression. The execution of the expression is not dependent upon the variable. The variable is just where the result of the expression is stored.
 
x = doSomething();
AnswerRe: Does anyone know this c plus plus knowledge? [modified]memberJackDingler16 Jan '13 - 11:19 
Your line with "CTempLock (&(this->m_Lock));" will create an unnamed variable of type CTempLock, call the destructor specified, and then call the destructor and destroy the object.
 
As another poster pointed out, using a constructor reference in this way, is supported as a means to pass temporary objects to a function.
 
The temporary object only exists on the stack, long enough to make a function call, that is intended to use the temporary object as a reference.

modified 16 Jan '13 - 17:28.

GeneralRe: Does anyone know this c plus plus knowledge?groupyu-jian16 Jan '13 - 17:50 
Right. Perhaps, it can use this way to do something in the constructor function of CTempLock.
GeneralRe: Does anyone know this c plus plus knowledge?memberJackDingler17 Jan '13 - 5:15 
Yes.
 
1. The object is created on the stack.
2. The constructor is called.
3. The destructor is called.
4. The object is then forgotten.
 
The example you provided is a good demo of how you can introduce locking bugs. Because the object goes out of scope right away, it doesn't really do anything useful.
 
The proper way to do it is:
CTempLock Lock(&(this->m_Lock));
 
If you do something like this...
 
void ProcessLock(const CTempLock & TempLock)
{
  // do stuff to TempLock here....
}
 
ProcessLock(CTempLock(&(this->m_Lock)));
 
Then the temporary object will exist for the lifetime of the call.
Questiondeque problem. Does this code has any problem? [solved] [modified]groupyu-jian14 Jan '13 - 3:47 
{
    CTempLock tempLock(&m_FrameListLock);
    if (m_FrameQueue.size() == 0)  return 0L;
 
    pFrameData = m_FrameQueue.front();
    m_FrameQueue.pop_front();
}
 
if (WaitForSingleObject(this->m_hCloseEvent, 0) == WAIT_OBJECT_0)
{
    return ZMD_OK;
}
 
try
{
    if (pFrameData != NULL)
    {
        if (pFrameData->lpData != NULL)
        {
            try
            {
                this->DistributeFrame(pFrameData->lpData, pFrameData->iSize);
                byte*  pBuf = reinterpret_cast<byte*>(pFrameData->lpData);
                delete[] pBuf;
            }
            catch (CException* e)
            {
                e->Delete();
            }
        }
        delete pFrameData;
        pFrameData = NULL;
    }
}
catch (CException* e)
{
    e->Delete();
}
 
}
 

There is a error that happens in the following code.
byte*  pBuf = reinterpret_cast<byte*>(pFrameData->lpData);
<b>delete[] pBuf;</b>
 
Just as the image, here.
https://www.dropbox.com/s/ckqkz88qnifus4g/Error.png
I find that the pFrameData->lpData is a wild buffer point.  I do not know when the buffer is released?  Or this deque has some problem?
 
The class is here.
 
class CStreamProcess
{
    HRESULT ProcessFrames();
 
    void DistributeFrame(const LPVOID const lpBuf, int  dwSize);
 
    HANDLE  m_hCloseEvent;
    HANDLE  m_hFrameProcessEvent;
    std::deque<SZMDFrameData>   m_FrameQueue;
    CCriticalSection    m_FrameListLock;
};
 
--------------------
I have resolved this problem. Its a mistake of using CCriticalSection.

modified 15 Jan '13 - 3:35.

AnswerRe: deque problem. Does this code has any problem?mvpCPallini14 Jan '13 - 6:59 
Quote:
m_FrameQueue.pop_front();

The removed element is destroyed, see, for instance std::deque::pop_front at C++ reference[^].
Veni, vidi, vici.

GeneralRe: deque problem. Does this code has any problem?groupyu-jian14 Jan '13 - 13:50 
Hi CPallini,
 
Thank you very much. You help me greatly.
GeneralRe: deque problem. Does this code has any problem?groupyu-jian14 Jan '13 - 16:02 
Not this problem, I made a test that has a temporary class. CMyClass. When pop_front() the desconstructor function of class CMyClass will not be called.
QuestionCDC Problem with coordinatesmemberArgonia14 Jan '13 - 1:50 
Hello,
I need to add a string on top / on bottom of a few drown GDI objects on printing. So far i override the OnPrint function.The problem i am facing is to decide where the text should be added in the CDC (i cant find the coordinates needed for TextOut)
I tried with CDC::GetBoundsRect(&dcRect, 0); but in dcRect i get nothing but zeros and the function returns 1. I think its returning DCB_RESET but i am not sure.
I tried with GetCurrentBitmap and GetBitmapDimension but still i get CSize variable with nothing but zeros.
All help is welcome Smile | :)
AnswerRe: CDC Problem with coordinatesmemberArgonia14 Jan '13 - 21:39 
The best thing i found is in the Microsoft Superpad example on the next link
Superpad
You can see how to put Header / Footer in it.
GeneralRe: CDC Problem with coordinatesmemberVaclav_Sal15 Jan '13 - 9:53 
Using API In MFC OnDraw
 
TextOut(pDC->GetSafeHdc(),1, 20, "HELLO HELLO", 11);
 
I am not sure if that will print alligned properly.
GeneralRe: CDC Problem with coordinatesmemberArgonia15 Jan '13 - 21:23 
My problem is finding the right coordinates for the TextOut function but after a talk with my Team manager we decided its better to be done as a header / footer.
Before that i just wanted to get the BoundRectangle with the hopes that it will be describing only the part in the page where the elements will be drown not the whole page itself.
I was wondering if there is a way to get out of the CDC member information about the position of the elements or something like that but i couldn't find any.
QuestionDhcpRequestParams()memberMan in the mirror13 Jan '13 - 19:46 
I want to use the function DhcpRequestParams() to get some information from the DHCP Server,but failes.
 
Any can help me?
Examples are best.
AnswerRe: DhcpRequestParams()mvpRichard MacCutchan13 Jan '13 - 22:11 
Try http://msdn.microsoft.com/en-us/library/windows/desktop/aa363345(v=vs.85).aspx[^].
One of these days I'm going to think of a really clever signature.

QuestionSOLVED From HANDLE to BITMAPINFO - another basic question for gurus [modified]memberVaclav_Sal13 Jan '13 - 5:30 
<pre lang="text">Found this very useful piece of code to get bitmap info from handle and would like to know HOW it works.
I think if I get how the LPBITAMPINFO gets filled I probably will also understand why using global handle is necessary. Or maybe not.</pre>
 
               // a DIB is in the clipboard, draw it out
               GLOBALHANDLE      hGMem ;
               LPBITMAPINFO      lpBI ;
               void*               pDIBBits;
               OpenClipboard() ;
               hGMem = GetClipboardData(CF_DIB) ;
               ASSERT(hGMem);
               TRACE("\nfills LPBITMAPINFO");
               lpBI = (LPBITMAPINFO)GlobalLock(hGMem) ;
 
Appreciate any help.
CHeers Vaclav

-- modified 15 Jan '13 - 15:54.
AnswerRe: From HANDLE to BITMAPINFO - another basic question for gurusmvpRichard MacCutchan13 Jan '13 - 5:44 
// a DIB is in the clipboard, draw it out
GLOBALHANDLE      hGMem ;    // create a global handle
LPBITMAPINFO      lpBI ;     // a pointer to the resultant bitmap
void*             pDIBBits;  // a pointer to the contents of the bitmap

OpenClipboard() ;                   // open the clipboard
hGMem = GetClipboardData(CF_DIB) ;  // get a handle (pointer) to the data in the clipboard
ASSERT(hGMem);                      // make sure it is valid
TRACE("\nfills LPBITMAPINFO"); 
lpBI = (LPBITMAPINFO)GlobalLock(hGMem) ; // lock that memory block and return a pointer to the DIB
At this point you can copy the memory block pointed to by lpBI into your program's address space and process it as required. You should then unlock and release hGMem (which is a system resource), and release the clipboard so other applications can use it.
One of these days I'm going to think of a really clever signature.

GeneralRe: From HANDLE to BITMAPINFO - another basic question for gurusmemberVaclav_Sal13 Jan '13 - 6:08 
Richard,
thanks for adding the comments.
I am still unclear how you get from HANDLE (pointer)   - returned by GetClipboardData to BITMAPINFO (pointer).
 

I guess I still do not get the casting.

This may be to stupid , but why   this would not work?
 
lpBI = (LPBITMAPINFO) GetCLipboardData(CF_DIB)
 
Maybe the key is really in usage of GLOBALHANDLE.
GeneralRe: From HANDLE to BITMAPINFO - another basic question for gurusmvpRichard MacCutchan13 Jan '13 - 6:32 
Vaclav_Sal wrote:
Maybe the key is really in usage of GLOBALHANDLE.
Exactly so. The GetCLipboardData() function returns a global handle, and you then need to use the GlobalLock() function to get a pointer to addressable memory. Remember that HANDLEs are 'opaque' types which you cannot use directly, even though they may at times point to some real memory. This is because they are owned by the Windows system and their contents at any one time is not guaranteed to be useful in user space.
One of these days I'm going to think of a really clever signature.

QuestionHow to get detail error info from E_FAIL?memberFalconapollo11 Jan '13 - 21:23 
When I use ATL in MFC Application(Don't ask me why, just because I like), sometimes I got the error code: E_FAIL. However, it's almost useless for me to locate the specific reason.
 
I have googled so many times, but found nothing related. I thought there should be something like try{} catch{} in ATL.
 
Here's some sample code:
 
CAxWindow  m_wndView;  // ActiveX host window class.
CComPtr<IWMPPlayer>  m_spWMPPlayer;  // Smart pointer to IWMPPlayer interface.

AtlAxWinInit();
CComPtr<IAxWinHostWindow>  spHost;
HRESULT  hr;
CRect rcClient;
GetClientRect(&rcClient);
m_wndView.Create(m_hWnd, rcClient, NULL, WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN, WS_EX_CLIENTEDGE);
//when I switch to Static Link to ATL from Dynamic Link to ATL, I always get E_FAIL
hr = m_wndView.QueryHost(&spHost);

AnswerRe: How to get detail error info from E_FAIL?member«_Superman_»11 Jan '13 - 23:43 
Use the _com_error class.
Construct an object of this class by passing in the HRESULT value and then use its WCode or ErrorMessage methods to get the error code mapped to the HRESULT value.
«_Superman 
I love work. It gives me something to do between weekends.


Microsoft MVP (Visual C++) (October 2009 - September 2013)

Polymorphism in C

GeneralRe: How to get detail error info from E_FAIL?memberFalconapollo12 Jan '13 - 0:00 
Thank you for your reply.
 
I have did as what you said, but I only get the error message:
Unspecified error.
 
Here is my code:
_com_error err(hr);
auto  d = err.WCode();
auto s = err.Description();
auto msg = err.ErrorMessage();//Unspecified error

GeneralRe: How to get detail error info from E_FAIL?memberJochen Arndt13 Jan '13 - 21:05 
'Unspecified error' is the english error message for E_FAIL. There is no more information available.
AnswerRe: How to get detail error info from E_FAIL?memberArgonia14 Jan '13 - 2:01 
You can try with GetLastError and see if you can get better description of the error . The number returned from the function you can check in msdn.
Good luck Smile | :)
QuestionVideo Capture using DirectShow only works for first time.?membermbatra3110 Jan '13 - 20:25 
Hi,
 
I have developed an application which captures video stream using DirectShow. While capturing, video is displayed on the canvas area. This works fine for the first time. But when again clicking on Start capturing button, video is getting captured, it doesn't display in the canvas area. Don;t know whether actually the camera is capturing the video or not.
 
Anybody have any idea regarding this.?
 
Any help will be appreciated.!
 

Regards,
mbatra
AnswerRe: Video Capture using DirectShow only works for first time.?group_AnsHUMAN_ 11 Jan '13 - 2:05 
You can debug to check if the code flow path is different from the first one in the second case.
If this doesn't help consider reinitialization of variables you are using before you display the video on the canvas.
You talk about Being HUMAN. I have it in my name
AnsHUMAN

AnswerRe: Video Capture using DirectShow only works for first time.?memberVaclav_Sal14 Jan '13 - 16:10 
Can you post some of your code?
I am using VFW API and OpenCV and debugging real time video can be a challenge.
What works for me is using temporary displays in step thru debug mode.
Questionhow to unsigned int64 to two unsigned int32 valuesmembervishalgpt9 Jan '13 - 22:22 
How to convert _uint64 into two _uint32 values and vice versa.
Regards,
Vishal

AnswerRe: how to unsigned int64 to two unsigned int32 valuesmemberJochen Arndt9 Jan '13 - 23:06 
By shifting the high part and casting:
 
_uint64 ui64 = 1234;
_uint32 lo = (_uint32)ui64;
_uint32 hi = (_uint32)(ui64 >> 32);
 
ui64 = (_uint64)lo | ((_uint64)hi) << 32;
 
[EDIT:] Added code formatting.
GeneralRe: how to unsigned int64 to two unsigned int32 valuesmembervishalgpt9 Jan '13 - 23:32 
does it take endianness into consideration, (Little/Big Endian)
Regards,
Vishal

GeneralRe: how to unsigned int64 to two unsigned int32 valuesmemberJochen Arndt9 Jan '13 - 23:58 
Yes, because the endianess does not care for the used logical operations.
 
If you think of multiplication / division instead of the shift operations and of addition instead of the OR operation it should be clear. The operation values are just high or low parts where the internally used bit or byte order does not care. Casting is similar (extending with high zeroes upon up-casting and masking out the lower bits upon down-casting).
GeneralRe: how to unsigned int64 to two unsigned int32 valuesmembervishalgpt10 Jan '13 - 0:08 
Thank you.. Smile | :)
Regards,
Vishal

AnswerRe: [SOLVED] how to unsigned int64 to two unsigned int32 valuesmember«_Superman_»10 Jan '13 - 18:39 
Here is another way to do it using the LARGE_INTEGER[^] union.
LARGE_INTEGER lint;
lint.QuadPart = 12345;  // Assigning 64-bit value;
// lint.LowPart and lint.HighPart can now be used to split the value;
«_Superman 
I love work. It gives me something to do between weekends.


Microsoft MVP (Visual C++) (October 2009 - September 2013)

Polymorphism in C

GeneralRe: [SOLVED] how to unsigned int64 to two unsigned int32 valuesmembervishalgpt14 Jan '13 - 15:25 
I too came across the union while using GetFileSize function.
 
does it produces same result in little endian and big endian systems.
 
as i want this for encryption section, where i had to convert 64bit unsigned integer to two 32 bit unsigned integer and vice versa,
 
So looking for results on little endian and big endian system result.
Regards,
Vishal

GeneralRe: [SOLVED] how to unsigned int64 to two unsigned int32 valuesmember«_Superman_»14 Jan '13 - 17:55 
Yes, this will give you correct results irrespective of the endian-ness.
«_Superman 
I love work. It gives me something to do between weekends.


Microsoft MVP (Visual C++) (October 2009 - September 2013)

Polymorphism in C

GeneralRe: [SOLVED] how to unsigned int64 to two unsigned int32 valuesmembervishalgpt14 Jan '13 - 19:01 
very very thank you sir.
Regards,
Vishal

QuestionHTTP server in C. How to implement Keep-Alive?memberjohanm_29 Jan '13 - 20:02 
I'm busy with my own http server implementation on an embedded platform. Technically the server is HTTP 1.0 compliant, and therefore it expects the the client to send the header "Connection: Keep-Alive" to keep the connection open.
 
The implementation looks like this. I removed the code that parses the HTTP header and performs the request, to keep the post as short as possible:
 

 
int Service_Request(int conn) {
    
        struct ReqInfo reqinfo;
        volatile int resource = 0;
        int retval = 0;
        Req_Result req_result = GOT_REQ;
        
        InitReqInfo(&reqinfo);
    
        /* while we still have HTTP requests to process */
        while (req_result == GOT_REQ)
        {
            
            /* Get HTTP request, there are 3 different return values:
             * GOT_REQ: we got a valid HTTP request
             * TIMEOUT_REQ we timed out waiting for a request
             * ERROR_REQ there was some error receiving from the socket
             * usually because the connection was closed by the peer*/
            req_result = Get_Request(conn, &reqinfo);
            if ( req_result == TIMEOUT_REQ)
            {
                /* timed out waiting for the client, exit */
                retval = 0;
                break;
            }
            else if (req_result == ERROR_REQ)
            {
                /* some error, exit */
                retval = -1;
                break;
            }
            /* Process the request GET, PUT and POST is supported*/
            if (reqinfo.method == GET)
            {
                /* code to handle GET*/
            }
            /* PUT and POST are handled in the same way */
            else if ((reqinfo.method == PUT) || (reqinfo.method == POST) )
            {
                /* Code to handle PUT and POST*/        
            }
            else
            {
                /* not supported, code should never get here */
                reqinfo.status = 501;
                Return_Error_Msg(conn, &reqinfo);
            }
            /*Diag_Msg("Client Request: \r\n");
            Diag_Msg(reqinfo.clientRequest);*/
            
            /*
             * the reqinfo.keep_alive flag will be set to 1 if the
             * "Connection: Keep-Alive" header was sent by the client
             */
            if(reqinfo.keep_alive == 0)
            {
                break;
            }
    
            reqinfo.keep_alive_max--;
            if(reqinfo.keep_alive_max <= 0 )
            {
                /*
                 * the connection has been reused for the maxmum amount of times, stop
                 */
                break;
            }
            /*
             * If we get here, we will clear the memory used for the client request
             * and go to the beginning of the while loop to receive another request
             */
            Writeline(conn,"\r\n",2);
            FreeReqInfo(&reqinfo);
            
        }
        FreeReqInfo(&reqinfo);
        return (retval);
    }
 

The Get_Request function looks like this:
 
Req_Result Get_Request(int conn, struct ReqInfo * reqinfo) {
    
        char buffer[MAX_REQ_LINE] = {0};
        int    rval;
        fd_set fds;
        struct timeval tv;
    
    
        /* Set timeout to 5 seconds if this is the first request since the client connected, wait 5 seconds
         * Otherwise, wait 5ms */
        if(reqinfo->first_request == 1)
        {
            tv.tv_sec = 5;
            tv.tv_usec = 0;
            reqinfo->first_request = 0;
        }
        else
        {
            tv.tv_sec = reqinfo->keep_alive_timeout;
            tv.tv_usec = 0;
        }
    
        /* Loop through request headers. If we have a simple request,
        then we will loop only once. Otherwise, we will loop until
        we receive a blank line which signifies the end of the headers,
        or until select() times out, whichever is sooner.                */
        do {
    
        /* Reset file descriptor set */
    
        FD_ZERO(&fds);
        FD_SET (conn, &fds);
    
    
        /* Wait until the timeout to see if input is ready */
    
        rval = select(conn + 1, &fds, NULL, NULL, &tv);
    
    
        /* Take appropriate action based on return from select() */
    
        if ( rval < 0 )
        {
          Diag_Msg("Error calling select() in get_request()");
          return (ERROR_REQ);
        }
        else if ( rval == 0 ) {
    
          /* input not ready after timeout */
    
          return (TIMEOUT_REQ);
    
        }
        else {
    
          /* We have an input line waiting, so retrieve it */
            memset(buffer,0,MAX_REQ_LINE - 1);
          if(Readline(conn, buffer, MAX_REQ_LINE - 1) == -1)
          {
                return (ERROR_REQ);
          }
          if(reqinfo->clientRequest == NULL)
          {
                reqinfo->clientRequest = calloc(MAX_REQ_LINE - 1, sizeof(char));
                strncpy(reqinfo->clientRequest,buffer,MAX_REQ_LINE - 1);
          }
          else
          {
                strncat(reqinfo->clientRequest,buffer,MAX_REQ_LINE - 1);
          }
          Trim(buffer);
    
          if ( buffer[0] == '\0' )
            break;
    
          if ( Parse_HTTP_Header(buffer, reqinfo) )
            break;
        }
        } while ( reqinfo->type != SIMPLE );
    
        return (GOT_REQ);
    }
 

 
To describe the workings of this server in English: The server receives the first request. It parses the headers, if it finds the "Connection: Keep-Alive" header, it sets a flag. The server proceeds to process this request. WHen it is done it checks the keep-alive flag. If it is cleared, the server closes the connection. If set the server performs a clean-up operation and the proceeds to wait for another request over the same connection. And so on.
 
I tested this with curl:
 
C:\curl>curl -v -H "Connection: Keep-Alive" --data-binary ( at )vid1.bin 10.84.67.129/s1p0:1/vid[1-2].bin
 
    [1/2]: 10.84.67.129/s1p0:1/vid1.bin --> <stdout>
    --_curl_--10.84.67.129/s1p0:1/vid1.bin
    * About to connect() to 10.84.67.129 port 80 (#0)
    * Trying 10.84.67.129...
    * connected
    * Connected to 10.84.67.129 (10.84.67.129) port 80 (#0)
    > POST /s1p0:1/vid1.bin HTTP/1.1
    > User-Agent: curl/7.28.1
    > Host: 10.84.67.129
    > Accept: */*
    > Connection: Keep-Alive
    > Content-Length: 51200
    > Content-Type: application/x-www-form-urlencoded
    > Expect: 100-continue
    >
    * HTTP 1.0, assume close after body
    < HTTP/1.0 100 Continue
    * HTTP 1.0, assume close after body
    < HTTP/1.0 200 OK
    < Server: DTSVU v0.1
    < Content-Type: text/html
    * HTTP/1.0 connection set to keep alive!
    < Connection: Keep-Alive
    < Keep-Alive: timeout=5, max=10
    <
    * Connection #0 to host 10.84.67.129 left intact
 
    [2/2]: 10.84.67.129/s1p0:1/vid2.bin --> <stdout>
    --_curl_--10.84.67.129/s1p0:1/vid2.bin
    * Connection #0 seems to be dead!
    * Closing connection #0
    * About to connect() to 10.84.67.129 port 80 (#0)
    * Trying 10.84.67.129...
    * connected
    * Connected to 10.84.67.129 (10.84.67.129) port 80 (#0)
    > POST /s1p0:1/vid2.bin HTTP/1.1
    > User-Agent: curl/7.28.1
    > Host: 10.84.67.129
    > Accept: */*
    > Connection: Keep-Alive
    > Content-Length: 51200
    > Content-Type: application/x-www-form-urlencoded
    > Expect: 100-continue
    >
    * HTTP 1.0, assume close after body
    < HTTP/1.0 100 Continue
    * HTTP 1.0, assume close after body
    < HTTP/1.0 200 OK
    < Server: DTSVU v0.1
    < Content-Type: text/html
    * HTTP/1.0 connection set to keep alive!
    < Connection: Keep-Alive
    < Keep-Alive: timeout=5, max=10
    <
    * Connection #0 to host 10.84.67.129 left intact
    * Closing connection #
 

 
As you can see, curl says: Connection #0 seems to be dead! after the first request is completed. It then proceeds to close the connection and opens a new one. I'm sure I implemented the HTTP 1.0 keep-alive functionality correctly. SO my question is: what does curl expect over the connection after the first request is completed? Why does it decide the connection is dead?
 
PS the above code was adapted from http://www.paulgriffiths.net/program/c/webserv.php
SuggestionRe: HTTP server in C. How to implement Keep-Alive?mvpRichard MacCutchan9 Jan '13 - 22:24 
This does not really have anything to do with C/C++; you may get a better response in the Web Development forum[^].
One of these days I'm going to think of a really clever signature.

GeneralRe: HTTP server in C. How to implement Keep-Alive?memberjohanm_210 Jan '13 - 1:17 
Sorry about about posting in the wrong forum. Could a moderator please move it?
 
I solved it myself. If the server replies with HTTP/1.1 and "Content-Length: 0", curl reuses the connection. My server reply lookes like this
 
HTTP/1.1 100 Continue
HTTP/1.1 200 OK
Server: DTSVU v0.1
Content-Type: text/html
Connection: Keep-Alive
Keep-Alive: timeout=1, max=95
Content-Length: 0
 
after the 5th reuse of the connection.
QuestionProblem loading non-default wabmemberMember 8689269 Jan '13 - 2:31 
Hi
I'm having trouble trying to load a non-default .wab file (I know it's old hat but need to keep it going for my XP users). I'm running it on Vista and although I'm supplying a filename it keeps loading my Vista Contacts instead instead of the specific wab addresses.
It must be going wrong around here (mostly stock code from the msdn sample code):
 
// (pszFileName is const char *)
 
if(m_hinstWAB)
{
// if we loaded the dll, get the entry point
//
m_lpfnWABOpen = (LPWABOPEN) GetProcAddress(m_hinstWAB, "WABOpen");
 
if(m_lpfnWABOpen)
{
HRESULT hr = E_FAIL;
WAB_PARAM wp = {0};
wp.cbSize = sizeof(WAB_PARAM);
wp.szFileName = (LPTSTR) (LPCTSTR) pszFileName;
 
// if we choose not to pass in a WAB_PARAM object,
// the default WAB file will be opened up
//
 
if(m_lpfnWABOpen(&m_lpAdrBook,&m_lpWABObject,&wp,0)==S_OK)
m_bInitialized = TRUE;

}
As usual, any help much appreciated.
Greg
AnswerRe: Problem loading non-default wabmemberCode-o-mat10 Jan '13 - 2:06 
Why is this conversion needed:
Member 868926 wrote:
wp.szFileName = (LPTSTR) (LPCTSTR) pszFileName;
?
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> If it doesn't matter, it's antimatter.<

GeneralRe: Problem loading non-default wabmemberMember 86892611 Jan '13 - 6:05 
Good point, well I'm now trying:
 
wp.szFileName = "C:\\Jim.wab";
 
as I know that wab exists there but it still isn't loading it.
G
GeneralRe: Problem loading non-default wabmemberCode-o-mat11 Jan '13 - 7:49 
Are you completely sure that is a correct WAB file and it is readable by the process (it has the required access rights and somesuch)?
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> If it doesn't matter, it's antimatter.<

GeneralRe: Problem loading non-default wabmemberMember 86892611 Jan '13 - 9:56 
Yes the wab is OK. If you doubleclick it Windows asks if you want to import the addresses.
Somehow the WabOpen bit just thinks I want the default Wab (although there isn't one in Vista) and isn't getting the filename. In the original code there was a 'GetNativePath()' call which isn't available - could it be to do with how I'm passing in the file location string?
G
GeneralRe: Problem loading non-default wabmemberCode-o-mat11 Jan '13 - 10:07 
As far as i remember the documentation says it will load the default if you pass NULL for the path, but you are not passing NULL but a seemingly correct path. Hmm...
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> If it doesn't matter, it's antimatter.<

GeneralRe: Problem loading non-default wabmemberCode-o-mat11 Jan '13 - 10:12 
If i check the documentation (http://msdn.microsoft.com/en-us/library/ms629458%28v=vs.85%29.aspx[^]) for WAB_PARAM, the szFileName member is declared to be LPTSTR. This suggests that depending on your target options, it might be a unicode or an ansii/mbcs string which then suggests that there might be a unicode and an ansii/mbcs version of the function (as with a lot of API methods throughout windows). When you query the function's pointer...are you sure you are getting the correct version?
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> If it doesn't matter, it's antimatter.<

GeneralRe: Problem loading non-default wabmemberMember 86892612 Jan '13 - 4:17 
I'm not sure - in the header file I can't see another version except WabOpenEx which I tried but didn't work.
I've noticed that my Contacts folder is actually receiving the wab addresses and getting bigger and bigger! So instead of opening the wab on its own it's adding them to the Contacts then opening those instead. Is this some undocumented Vista mechanism?
Thanks very much for everyone's conttributions so far.
G
GeneralRe: Problem loading non-default wabmemberCode-o-mat12 Jan '13 - 8:09 
Frankly, i don't know, sorry... Frown | :(
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> If it doesn't matter, it's antimatter.<

QuestionRe: Problem loading non-default wabmvpRichard MacCutchan11 Jan '13 - 6:41 
  1. Have you checked the actual error code returned from the WABOpen Function?
  2. Have you checked the documentation[^] for compatibility?
One of these days I'm going to think of a really clever signature.

AnswerRe: Problem loading non-default wabmemberMember 86892611 Jan '13 - 9:53 
It doesn't return an error, just loads my Vista Contacts instead. Compatability seems OK.
GeneralRe: Problem loading non-default wabmvpRichard MacCutchan11 Jan '13 - 23:17 
Have you tried removing the default contacts file to see if it works then? It's a long while since I used WAB and I never actually tried using the non-default file.
One of these days I'm going to think of a really clever signature.

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   


Advertise | Privacy | Mobile
Web04 | 2.6.130516.1 | Last Updated 21 May 2013
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid