Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8515511
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T05:09:59+00:00 2026-06-11T05:09:59+00:00

Alright so I have this code, and I pass it to an unmanaged dll,

  • 0

Alright so I have this code, and I pass it to an unmanaged dll, to which I only know the exports, and have some sample code. I’m getting back the correct string, but it’s followed by garbage bytes.

I’m basically translating code verbatim from a c++ example program that doesn’t have this issue. I’m assume there is something fundamental I am missing here, so if anyone could tell me what that is, I’d appreciate it.

Example C++ Code

void CDUKPT_TESTDlg::OnButton4() 
{
    // TODO: Add your control notification handler code here
    unsigned char dataout[1024],tmp[1024],ksn[20],keyval[20];
    int nRet,len;
    memset(dataout,0,sizeof(dataout));
    memset(ksn,0,sizeof(ksn));
    memset(keyval,0,sizeof(keyval));
    memset(tmp,0,sizeof(tmp));
    UpdateData(TRUE);

    two_one((unsigned char *)m_strCURKSN.GetBuffer(m_strCURKSN.GetLength()),m_strCURKSN.GetLength(),ksn);
    two_one((unsigned char *)m_strMACK.GetBuffer(m_strMACK.GetLength()),m_strMACK.GetLength(),keyval);
    two_one((unsigned char *)m_EncryptDat.GetBuffer(m_EncryptDat.GetLength()),m_EncryptDat.GetLength(),dataout);

    len=m_EncryptDat.GetLength()/2;
    //extern int __stdcall ExtractDat(unsigned char *input,
    //unsigned short len,unsigned char *output,unsigned char *key,
    //unsigned char *ksn);
    nRet=ExtractDat(dataout,len,tmp,keyval,ksn); //External Call
    //Good string+bad trailing data comes back in tmp
    m_Result=tmp;
    UpdateData(FALSE);
}

This code spits out this ܉Òdÿo 

Here is my VB.Net Code

Public Function Encrypt(ByVal inp As String) As String
    Dim tmpSB As New StringBuilder
    Dim i As Integer
    Dim tKsn As Char() = TwoOne(StrCurKsn)
    For i = tKsn.Length To 19
        tKsn = tKsn + Chr(0)
    Next
    Dim tMack As Char() = TwoOne(StrMack)
    For i = tMack.Length To 19
        tMack = tMack + Chr(0)
    Next
    Dim tEnc As Char() = TwoOne(inp)
    For i = tEnc.Length To 1023
        tEnc = tEnc + Chr(0)
    Next
    Dim len As Integer = tEnc.Length / 2

    Dim tmpStr(1023) As Char
    Array.Clear(tmpStr, 0, 1024)
    Dim tmpPtr = Marshal.StringToHGlobalAnsi(tmpStr)

    Dim nRet = ExtractDat(tEnc, len, tmpPtr, tMack, tKsn)

    tmpStr = Marshal.PtrToStringAnsi(tmpPtr)
    Dim tsl = tmpStr.Length
    Encrypt = tmpStr
End Function

This code spits this out

܉Òdÿo ålUäÙålUäÙålUäÙålUäÙålUäÙålUäÙålUäÙ

So I get the right string, but it’s followed by a repeating string of garbage characters.
I’m hoping I’ve done something blatantly wrong here, but I’ve tried pulling the data as bytes, and chars, and converting in many different methods, and I can’t seem to get rid of those characters…Also, ExtractDat doesn’t return the length of the string(not a problem, as it’s not supposed to, which is really annoying).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T05:10:01+00:00Added an answer on June 11, 2026 at 5:10 am

    Turns out the dll was bad, so after I got a fresh compile from the vendor it seemed to work.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Alright, I have this program to sparse code in Newick Format, which extracts both
Alright, so I have this collision detection code, and I'm trying to push the
Alright I know this is more than likely a amateur question but I have
I have this code, it looks alright and is really basic, but i can't
Alright, so I have this bit of code, and when I make the request,
Alright, this problem seems to be way above my head! I have this code:
I have been struggling to understand some pieces of this code. It asks to
Alright I have the MYSQL query code setup to pull this information out of
I have written this piece of code here and I have linked it alright
Alright, I wanna know why this code is working, I just realized that I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.