Thread: How can I get const from a variable?

  1. #46
    Registered User
    Join Date
    Jun 2015
    Posts
    1,640
    You should free the memory if you don't need it any more. My mistake was that I used free where I should have used efree.

  2. #47
    Registered User
    Join Date
    Feb 2011
    Posts
    96
    I can't tell you how much I appreciate your help (algorism especially).

    I finally got this thing to return a list of printer feeders in an array to the Web page.
    Again, it's PHP7 so I'm stuck inside a rather complex framework.

    Here's the last part for future reference:
    Code:
    #define BNLEN 24
    FILE *fp;
    DWORD dcRet;
    char (*pOut)[BNLEN]; // ptr to dynam array of 24-element char arrays
     
    // Get number of bin names.
    dcRet = DeviceCapabilities(resource->name, pi2->pPortName, DC_BINNAMES, NULL, NULL); // or pi2->pDevMode
    if (dcRet == (DWORD)-1){
    	sprintf(sRtn, "DeviceCapabilities failed: %u\n", GetLastError());				
    	RETURN_STRING(sRtn, 1);
    }
     
    // Alloc and fill bin names.
    pOut = emalloc(dcRet * BNLEN);
    dcRet = DeviceCapabilities(resource->name, pi2->pPortName, DC_BINNAMES, (LPTSTR)pOut, NULL); // or pi2->pDevMode
    if (dcRet == (DWORD)-1){
    	sprintf(sRtn, "DeviceCapabilities failed: %u\n", GetLastError());				
    	RETURN_STRING(sRtn, 1);
    }
    
    if(array_init(return_value) == FAILURE) RETURN_FALSE;
    for (DWORD i = 0; i < dcRet; i++) {
    	add_index_string(return_value, i, pOut[i]);				
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Changing a const variable?
    By jw232 in forum C++ Programming
    Replies: 14
    Last Post: 09-01-2008, 09:53 AM
  2. how to make a non const copy of a const variable?
    By sept in forum C++ Programming
    Replies: 6
    Last Post: 02-25-2008, 02:11 AM
  3. const variable...
    By technosavvy in forum C Programming
    Replies: 9
    Last Post: 02-18-2008, 06:05 AM
  4. const variable
    By vaibhav in forum C++ Programming
    Replies: 3
    Last Post: 10-24-2005, 08:06 AM
  5. problem with the const variable
    By ssharish in forum C Programming
    Replies: 2
    Last Post: 01-28-2005, 09:53 AM

Tags for this Thread