Thread: pointer to pointer manipulation

  1. #1
    Registered User
    Join Date
    Jul 2004
    Posts
    222

    pointer to pointer manipulation

    I'm having some confusion trying to access pAdditionalFileNames in the function below. Basically I have been passing that function as shown:
    Code:
    			wstring additions[3];
    			additions[0] = L"black.dll";
    			additions[1] = L"white.dll";
    			additions[2] = L"yellow.dll";
    			//additions[3] = L"green.dll";
    
    			PdfPrnInstCopyDriverFilesExW(L"E:\\test",
    									L"E:\\Research\\Hello",
    									(const WCHAR**) additions,
                                                                             sizeof(additions));
    into the function as shown:

    Code:
    BOOL someFunc(const WCHAR* destFolder, const WCHAR* pSourceFolder,  const WCHAR** pAdditionalFileNames,  size_t nAdditionalFileNamesSize)
    {
    	// Determine amount of additional files passed to the function by
    	// dividing the amount of bytes needed by amount of bytes per entry (32 bytes/entry)
    	size_t nEntries = nAdditionalFileNamesSize/32;
    
    	wcout << "nAdditionalFileNamesSize = " << nAdditionalFileNamesSize << endl;
    
    	/*wstring *pAddFileNamesStrings = (wstring*) pAdditionalFileNames;
    	for (int i=1; i < 5; i++)
    	{
    		wcout << "file " << i << " = " << *pAddFileNamesStrings << endl;
    		pAddFileNamesStrings++;
    	}*/
    	
    
    	return TRUE;
    }
    I have tried the code highlighted in green to address the pointer to pointer, however, it seems that I am not addressing the memory properly, hence runtime errors during testing. Does anyone have pointers on ways to obtain the contents of pAdditionalFileNames? Thanks.

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    You pass the array wrong and you access the array wrong.
    Pass it as a simple WCHAR* pointer (unless wstring is a typedef for WCHAR*?), and access it using str[n].
    If it's a 2D array, then the easiest way is to pass dimensions, like:

    const WCHAR (*pAdditionalFileNames)[3]

    But the question begs: are you passing a string to Windows API? If so, then you must pass a pointer to the first element.
    If you are passing it to a C++ function, then use std::vector<std::string> and a (const) reference to that.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    I'd expect wstring to be std::wstring, i.e. std::basic_string<wchar_t>. Of course, that makes the cast of the array to WCHAR** all the more horrible.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  4. #4
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    I expect the same thing, but I can't be 100&#37; sure due to the C-style casts...
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 6
    Last Post: 05-15-2009, 08:38 AM
  2. Why does C need pointer conversion
    By password636 in forum C Programming
    Replies: 2
    Last Post: 04-10-2009, 07:33 AM
  3. Pointer Manipulation with strcat()
    By radiohead in forum C Programming
    Replies: 3
    Last Post: 03-03-2006, 07:17 AM
  4. scope of a pointer?
    By Syneris in forum C++ Programming
    Replies: 6
    Last Post: 12-29-2005, 09:40 PM
  5. Struct *** initialization
    By Saravanan in forum C Programming
    Replies: 20
    Last Post: 10-09-2003, 12:04 PM