Click here to Skip to main content
15,885,032 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Experts,

I getting problem converting vb6.0 code into c#


Declare Function GSSymbol Lib "GSWDLL32.DLL" (ByVal fxOrg#, ByVal fyOrg#, ByVal nSymbol&, ByVal nClr&) As Long


Thanks,
T.Ramesh Kumar


What I have tried:

[DllImport("GSWDLL32.DLL", SetLastError = true)]
        public static extern long GSSymbol(
            long fxOrg, 
            long fyOrg, 
            long nSymbol, 
            long nClr
       );



error :-
<pre>Managed Debugging Assistant 'PInvokeStackImbalance' : 'A call to PInvoke function 'CTTS!CTTS.CTTSUtils::GSSymbol' has unbalanced the stack. This is likely because the managed PInvoke signature does not match the unmanaged target signature. Check that the calling convention and parameters of the PInvoke signature match the 
Posted
Updated 16-Nov-20 22:36pm

I'm not a fan of converting from VB6, rather I use it as a proof-of-concept or "specification" for the final .NET application - useful source of test results too.

In the light of that approach you might want to consider replacing the use of GSWDLL32 with something more modern - e.g. Chart Class (System.Windows.Forms.DataVisualization.Charting) | Microsoft Docs[^]
 
Share this answer
 
Comments
Maciej Los 17-Nov-20 5:21am    
Good advice!
Your type mapping is wrong. The VB6 declaration is:
VB
... (ByVal fxOrg As Double, ByVal fyOrg As Double, ByVal nSymbol As Long, ByVal nClr As Long) As Long
Type Characters - Visual Basic | Microsoft Docs[^]

But Long in VB6 refers to a 32-bit integer. In .NET, that's an Int32, which maps to Integer in VB.NET and int in C#.

So to match your VB6 code, your C# declaration should be:
C#
[DllImport("GSWDLL32.DLL", SetLastError = true)]
public static extern int GSSymbol(
    double fxOrg, 
    double fyOrg, 
    int nSymbol, 
    int nClr
);
 
Share this answer
 
Comments
Maciej Los 17-Nov-20 5:21am    
5ed!
T. Ramesh Kumar 17-Nov-20 10:32am    
Thank u to all "Experts" for ur good advice.
let's try all codes one by one.
Check this out: DllImportAttribute Class (System.Runtime.InteropServices) | Microsoft Docs[^].

There's few fields to set:
BestFitMapping
CallingConvention
CharSet
EntryPoint
ExactSpelling
PreserveSig
SetLastError
ThrowOnUnmappableChar
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900