Jump to content
  • Advertisement
Sign in to follow this  
EonStrife

Problem in #Import (VC++)

This topic is 4491 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi guys... I've got a dll, called Encryption.dll. I got Exception when I use it in my PC, but when I transfer the program to other PC, it works fine ! Here's the detail : Encryption.tlh
// Created by Microsoft (R) C/C++ Compiler Version 12.00.9782.0 (f4c6d585).
//
// d:\program samples\060429\btserver\debug\Encryption.tlh
//
// C++ source equivalent of Win32 type library Encryption.dll
// compiler-generated file created 05/01/06 at 11:03:18 - DO NOT EDIT!

#pragma once
#pragma pack(push, 8)

#include <comdef.h>

namespace Encryption2 {

//
// Forward references and typedefs
//

struct __declspec(uuid("732a10c5-7c91-421f-a626-4a6335d74e6b"))
/* dual interface */ _Encrypt;
struct /* coclass */ Encrypt;

//
// Smart pointer typedef declarations
//

_COM_SMARTPTR_TYPEDEF(_Encrypt, __uuidof(_Encrypt));

//
// Type library items
//

struct __declspec(uuid("732a10c5-7c91-421f-a626-4a6335d74e6b"))
_Encrypt : IDispatch
{
    //
    // Wrapper methods for error-handling
    //

    _variant_t Encrypt (
        VARIANT * Source );
    _variant_t Decrypt (
        VARIANT * Source );

    //
    // Raw methods provided by interface
    //

    virtual HRESULT __stdcall raw_Encrypt (
        VARIANT * Source,
        VARIANT * _arg2 ) = 0;
    virtual HRESULT __stdcall raw_Decrypt (
        VARIANT * Source,
        VARIANT * _arg2 ) = 0;
};

struct __declspec(uuid("7e5acc22-3a01-4179-aba0-abf13a689aad"))
Encrypt;
    // [ default ] interface _Encrypt

//
// Wrapper method implementations
//

#include "d:\program samples\060429\btserver\debug\Encryption.tli"

} // namespace Encryption2

#pragma pack(pop)

Encryption.tli
// Created by Microsoft (R) C/C++ Compiler Version 12.00.9782.0 (f4c6d585).
//
// d:\program samples\060429\btserver\debug\Encryption.tli
//
// Wrapper implementations for Win32 type library Encryption.dll
// compiler-generated file created 05/01/06 at 11:03:18 - DO NOT EDIT!

#pragma once

//
// interface _Encrypt wrapper method implementations
//

inline _variant_t _Encrypt::Encrypt ( VARIANT * Source ) {
    VARIANT _result;
    VariantInit(&_result);
    HRESULT _hr = raw_Encrypt(Source, &_result);
    if (FAILED(_hr)) _com_issue_errorex(_hr, this, __uuidof(this));
    return _variant_t(_result, false);
}

inline _variant_t _Encrypt::Decrypt ( VARIANT * Source ) {
    VARIANT _result;
    VariantInit(&_result);
    HRESULT _hr = raw_Decrypt(Source, &_result);
    if (FAILED(_hr)) _com_issue_errorex(_hr, this, __uuidof(this));
    return _variant_t(_result, false);
}

And, here's my class : MyEnkrip.h
#define INITGUID
#import "Encryption.dll" rename_namespace("Encryption2")
using namespace Encryption2;


class MyEnkrip
{
public:
	//CString enkripsi(CString pt);
	MyEnkrip();
	~MyEnkrip();
	char* enkripsi(char *pt);
	char* dekripsi(char *pt);
};

MyEnkrip.cpp
#include "MyEnkrip.h"
#define COPYSTRING(s1, s2, len) {for(int i=0; i<len; i++){if(s2==0) {s1=0;break;}else s1=s2;}s1[len-1]=0;}
#define CREATEINSTANCE(sp,riid) { HRESULT _hr =sp.CreateInstance( __uuidof( riid ) ); if (FAILED(_hr)) _com_issue_error(_hr ); }

MyEnkrip::MyEnkrip()
{
	::CoInitialize(NULL);
}

MyEnkrip::~MyEnkrip()
{
	::CoUninitialize();
}

char* MyEnkrip::enkripsi(char *pt)
{
	_EncryptPtr x;
	
	//CREATEINSTANCE(x, Encrypt);
	x.CreateInstance(__uuidof(Encrypt));  
	
	char pas_baru[16];

	_variant_t inpu(pt);
	
	inpu.ChangeType(VT_BSTR);

	VARIANT b(inpu);
	
	_variant_t hasil;
	hasil=x->Encrypt(&b); //////THIS ONE IS THE PROBLEM
	
	hasil.ChangeType(VT_BSTR);
	COPYSTRING(pt, hasil.bstrVal, strlen(pt));
	x.Release();
	
	
	//return ct;
	return pt;
}

char* MyEnkrip::dekripsi(char *pt)
{
	_EncryptPtr x;
	x.CreateInstance(__uuidof(Encrypt));
	char pas_baru[16];
	//CString ct;
	
	_variant_t inpu(pt);
	inpu.ChangeType(VT_BSTR);
	VARIANT b(inpu);
	
	_variant_t hasil;
	hasil=x->Decrypt(&b);

	hasil.ChangeType(VT_BSTR);
	COPYSTRING(pt, hasil.bstrVal, strlen(pt));
	//ct=hasil.bstrVal;
	//strcpy(pt, ct);
	x.Release();
	
	
	//return ct;
	return pt;
}


It always throws exception in hasil=x->Encrypt(&b); instruction (But I believe that I already get error in CreateInstance, since that CREATEINSTANCE Macro throws error). What should I do ? Any advice ? Thanks.

Share this post


Link to post
Share on other sites
Advertisement
Two things:

1. Make sure Encryption.DLL is registered on the system.
2. Modify your CreateInstance so you record the HRESULT, then lookup the HRESULT online or on MSDN to see what it means.

If that doesn't solve the problem, post the HRESULT of your CreateInstance() call and we can help you further.

Robert

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!