Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ATL DLL
hi,
i have a native C++ dll and a virtual class("mycert") in it.I have an ATL dll project and i included the native dll into the ATL and create an interface for the 'mycert' .In mycert interface i have a function :
STDMETHODIMP Cmycert::setSignature(BYTE* data, SHORT size)
{
 
        cert = new mycert();
	ByteArray* barray = new ByteArray();
	for(int i=0;i<size;i++)
		(*barray)[i] = data[i];
	ASN1BitString* bitString = new ASN1BitString();
	bitString->setValue(*barray);
	cert->setSignature(bitString);
	
	return S_OK;
}
 
and in a c# project i include the ATL dll and call the above function:
byte[] data = new byte[3];
data[0] = 4;
data[1] = 6;
data[2] = 8;
mycertClass obj = new mycertClass();
obj.setSignature(ref data[0], 3);
 
when i run this code, it gives the following error:
 
"Runtime Error!

Program:
...dio 2008\Projects\myApplication\myApplication\bin\Debug\myApplication.vshost.exe

This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information."
 
my native c++ dll has lots of classes other than 'mycert' and they are not virtual, i can do the same operations on them successfully ,only mycert class cause this error. Am I missing something about virtual classes?
Can you help me please?
Posted 25-Feb-10 3:03am
bltfr448
Edited 3-Mar-10 4:44am
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Can you call your function
if it returns S_OK only ? Smile | :)
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

yes i can call it. I am calling the functions of the other interfaces but only this interface doesn't work.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

OK, it is not just a bit Smile | :)
 
Could you explain
why do you need a new mycert()
 
or what would you like to have in your function ? Smile | :)
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

mycert is the class in my native c++ dll so i should create an instance of it to use the functions of it . I don't create the instance of the mycertclass in the ATL with "new mycert()" code. ByteArray and ASN1BitString classes are also in the native dll and i can do operations with them, there is no problem with them. I am trying to call the setSignature function of the virtual mycert class in native C++ dll.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

Could you post the definition of the mycert class ? Smile | :)
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 6

#ifdef dll_EXPORTS
#define dll_API __declspec(dllexport)
#else
#define dll_API __declspec(dllimport)
#endif
class dll_API mycert : public Sequence
{
    public:
        mycert(void);
        mycert(string name);
        ~mycert();
        void setTCert(TCert* tCertVal);
        void setSigAlgorithm(AlgId* sigAlgVal);
        void setSignature(ASN1BitString* sigVal);
        TCert* getTBSCert();
        AlgId* getSigAlgorithm();
        ASN1BitString* getSignature();
        ASN1Base* makeCopy(void);
        bool decode(ByteArray input);
 
    private:
        TCert* tbsCert;
        AlgId* sigAlg;
        ASN1BitString* sign;
        void setUpElements();
};
i have only header files of the dll, it is not my own dll.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 7

It does not look to be a virtual class... Smile | :)
 
Is there an error
when you reduce the interface function to ? :
{
  mycert cert;
  return S_OK;
}
 
If you will get no error -
please read the documentation of mycert::setSignature(..)
 
(may be there is a limitation by the data length or format)
and try to call it with more "real" data Smile | :)
 
Elsewise I would test the DLL (mycert and mycert::setSignature)
from a C++ application directly, without any interface Smile | :)
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 8

I got no error with that code.
I change the code :
STDMETHODIMP Cmycert::setSignature(BYTE* data, SHORT size)
{   
        cert = new mycert();
	ByteArray barray;
	for(int i=0;i<size;i++)
		barray[i] = data[i];
	ASN1BitString* bitString = new ASN1BitString();
	bitString->setValue(barray);
	cert->setSignature(bitString);
	return S_OK;
}
 
because definition of setValue function of ASN1String class
" void setValue(ByteArray) "
but still it gives the same error.
Thank you very much for your help.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 9

You could also place an AfxMessageBox(_T("#<N>"));
 
after each line in this function to determinate the error source approximately Smile | :)
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 10

I put the line AfxMessageBox(_T("#<N>")) ,it gives the following error:
 
"fatal error C1189: #error : Building MFC application with /MD[d] (CRT dll version) requires MFC shared dll version. Please #define _AFXDLL or do not use /MD[d] c:\Program Files\Microsoft Visual Studio 9.0\VC\atlmfc\include\afx.h "
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 11

Smile | :) ...then MessageBox(NULL, _T("Line #<N>"), _T("We are inside :)"), MB_OK);
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 12

It worked. Thanks Eugen! There is a problem inside the for loop, but i can't understand ,same loop works correctly in other functions.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 13

OK Smile | :) Please try this body:
{
  BYTE byTest = data[1];
  return S_OK;
}
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 14

it is working, what should i do?
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 15

May be you should use ByteArray::Add(..) and not [..] ? Smile | :)
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 16

there is no Add function, there is an init function but it is protected.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 17

Could you post the definition of the class ? Smile | :)
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 18

class dll_API ByteArray
{
  public:
      ByteArray(int sz = 0);
      ByteArray(const ByteArray&);
      ~ByteArray();
      ByteArray& operator=(const ByteArray&);
      unsigned char& operator[](int)  throw (RangeException);
      string getHexString(bool);
      string getValueAsString();
      int getSize();
      static ByteArray concat(ByteArray,ByteArray);
      static bool copy(ByteArray, int, ByteArray &, int, int);
      static int compare(ByteArray, ByteArray);
 
  protected:
      void init(const unsigned char*, int);
      string char2Hex(unsigned char ch);
 
  private:
      unsigned char* data;
      int size;
};
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 19

OK Smile | :) Try to construct your instance as following:
{
...
  ByteArray arTemp(size); // pass the second parameter here :)
  // The loop
...
}
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 20

Wink | ;) it works, Eugen you are perfect. i am very thankful to you
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Maciej Los 315
1 OriginalGriff 273
2 Aajmot Sk 224
3 Marcin Kozub 210
4 Richard MacCutchan 200
0 OriginalGriff 7,853
1 Sergey Alexandrovich Kryukov 7,107
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,790


Advertise | Privacy | Mobile
Web04 | 2.8.1411023.1 | Last Updated 3 Mar 2010
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100