dll access help

This is a discussion on dll access help within the C++ Programming forums, part of the General Programming Boards category; hi! I am new to c++ and for a project i have to access a dll file. And in the ...

  1. #1
    Registered User
    Join Date
    May 2004
    Posts
    2

    Exclamation dll access help

    hi!
    I am new to c++ and for a project i have to access a dll file. And in the access details of this dll the company has given this help -

    Load dll and create the main interface (ILITWriter) using the CreateWriter() export.

    // CreateWriter method detail

    HRESULT CreateWriter(
    [out, retval] IUnknown** ppWriter
    );
    Parameter ppWriter - Pointer to interface pointer of new writer

    Could anybody pls tell me what they are actually want to say.Specifically what doest they mean with the term - "create the main interface (ILITWriter) using the CreateWriter() export." and how should i go about this.

    Thanxs,

  2. #2
    vae victus! skorman00's Avatar
    Join Date
    Nov 2003
    Posts
    594
    to load a dll, you can go through your options and settings and tell your linker to link the dll file.

    To use the function, try something like this
    Code:
    IWriter * pWriter;
    CreateWriter(&pWriter);
    I'm not positive that IWriter is the correct type you would want, but it looks like what they would use with the naming conventions they have.

  3. #3
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    [EDIT]
    Whoops, I thought you had to create the DLL. To use the CreateWriter() functions see these pages:
    http://msdn.microsoft.com/library/de...ilitwriter.asp
    http://msdn.microsoft.com/library/de...ilitwriter.asp
    [/EDIT]

    It is expecting you to return a COM object that implements the ILITWriter interface. If you have no knowledge of COM you are going to need to start with a tutorial.

    Here is the beginnings of an object that implements ILITWriter:
    Code:
    class CLITWriter : public ILITWriter
    {
    private:
      LONG m_cRefs;
    
    public:
    
    /* --IUnknown methods-- */
      STDMETHODIMP QueryInterface(REFIID riid, void ** ppv)
      {
      	if (ppv == NULL) return E_INVALIDARG;
    
      	if (IsEqualIID(riid, IID_IUnknown) || IsEqualIID(riid, IID_ILITWriter))
      	{
      		*ppv = (ILITWriter *) this;
      	}
      	else
      	{
      		*ppv = NULL;
      		return E_NOINTERFACE;
      	}
    
    	AddRef();
    	return NOERROR;
      }
    
      STDMETHODIMP_(ULONG) AddRef(void)
      {
      	return InterlockedIncrement(&m_cRefs);
      }
    
      STDMETHODIMP_(ULONG) Release(void)
      {
      	if (InterlockedDecrement(&m_cRefs) == 0)
      	{
      		delete this;
      		return 0;
      	}
    
      	return m_cRefs;
      }
    
    /* --ILITWriter methods -- */
    
      STDMETHODIMP SetCallback(IUnknown * pCallback)
      {
        // code
      }
    
      STDMETHODIMP Create(const wchar_t* pwszLitFile, const wchar_t* pwszSourceBasePath,
                          const wchar_t* pwszSource, int iMinimumReaderVersion)
      {
        // code
      }
    
      // Rest of the ILITWriter methods
    };
    and here is an implementation of CreateWriter():
    Code:
    STDMETHODIMP CreateWriter(IUnknown** ppWriter)
    {
    	if (NULL == ppWriter)
    	{
    		return E_INVALIDARG;
    	}
    
    	CLITWriter * pLitWriter = new CLITWriter;
    
    	*ppWriter = (IUnknown *) pLitWriter;
    	
    	if (NULL == *ppWriter)
    	{
    		return E_OUTOFMEMORY;
    	}
    
    	return NOERROR;
    }
    Last edited by anonytmouse; 05-30-2004 at 04:22 PM.

  4. #4
    Registered User
    Join Date
    May 2004
    Posts
    2
    hye!
    thnxs for your help. i have started learning about COM .
    Could u explain what does u mean with this method of Create

    STDMETHODIMP Create(const wchar_t* pwszLitFile, const wchar_t* pwszSourceBasePath,
    const wchar_t* pwszSource, int iMinimumReaderVersion)
    {
    // code
    }

    i.e what code we have to written in this method.
    bye!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. DLL Access Violation?
    By durban in forum C++ Programming
    Replies: 12
    Last Post: 10-04-2005, 06:55 PM
  2. dll communicating between each other
    By cloudy in forum C++ Programming
    Replies: 5
    Last Post: 06-17-2005, 03:20 AM
  3. DLL and std::string woes!
    By Magos in forum C++ Programming
    Replies: 7
    Last Post: 09-08-2004, 01:34 PM
  4. Access VB DLL from C++ ?
    By torbjoen in forum Windows Programming
    Replies: 3
    Last Post: 12-05-2002, 07:14 AM
  5. DLL & free() Heap Access Violation
    By kuphryn in forum Windows Programming
    Replies: 0
    Last Post: 08-13-2002, 11:45 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21