dbServer access in Bandol RC 2 & some other issues

This forum is meant for questions and discussions about the X# language and tools
ic2
Posts: 1805
Joined: Sun Feb 28, 2016 11:30 pm
Location: Holland

dbServer access in Bandol RC 2 & some other issues

Post by ic2 »

Hello Chris, Robert,

Thanks for the explanation and the workarounds. However, adding the code like this (with or without semicolon) :

cConn:=CurDrive() + ":" + CurDir()
[DllImport("ace32.dll", CharSet := CharSet.Ansi)];
If lRemoteADS
ulRetVal:=AdsConnect60(cConn ,XSharp.ADS.ACE.ADS_REMOTE_SERVER, "adssys", Null, (Dword)XSharp.ADS.ACE.ADS_DEFAULT, hConn)

gives these 4 errors on the same line (the one in bold, with ADSConnect60 in it):

Error XS9002 Parser: mismatched input '(' expecting EOS (2X)
Error XS9002 Parser: unexpected CRLF, are you missing a token ?
Error XS9002 Parser: unexpected input 'CharSet.Ansi)'

Then I thought I should probably move it at the start of the containing method like with [System.Diagnostics.DebuggerHidden()] but when I do that it gives:

Error XS0601 The DllImport attribute must be specified on a method marked 'static' and 'extern'

The method is currently a Public Virtual Method and although I usually don't have specific reasons to make a method anything special (like in VO where a METHOD is simply a METHOD everywhere in my programs) some method types in X#/Vulcan have been chosen after some of the other ways failed. Which proves because when I make the method STATIC EXTERN as the error suggests I should do I get XS0179 'Method' cannot be extern and declare a body.

In short, I don't want to change my method type from 'working' to 'possible not working'.

I also tried including ADS.PRG which gives over 300 errors in the #region Constructor. When I remove the entire region only the above errors remain. Also I noticed that in ADS.PRG

PUBLIC STATIC METHOD AdsConnect60(strServerPath as string , usServerTypes as WORD, strUserName as string , strPassword as string , ulOptions as DWORD, phConnect out IntPtr ) as DWORD

is outcommented under // Unused methods. Is that correct?

Is it probably better to wait until the missing parts are added without the need to change my code further? Or would you like me to test the actual program with additional info how to deal with these new errors?

Dick
User avatar
robert
Posts: 4265
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

dbServer access in Bandol RC 2 & some other issues

Post by robert »

Dick,

You need to put the code that I showed not inside your current code but as a separate function in your source.
And I did not mean that you should include ADS.PRG in your code. This was for reference only.
And indeed the function is commented out, that is why it does not work ;).

Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
ic2
Posts: 1805
Joined: Sun Feb 28, 2016 11:30 pm
Location: Holland

dbServer access in Bandol RC 2 & some other issues

Post by ic2 »

You need to put the code that I showed not inside your current code but as a separate function in your source.
Hello Robert

Sorry, I still don't know how. If I just add a new program and tried a couple of combination of how to add the code which shouls solve the ADSConnect error.

You can skip to 4 (which compiles the added program but still doesn't solve the ADSConnect60 error....)

1 (with or without semicolon)

[DllImport("ace32.dll", CharSet := CharSet.Ansi)];

-->Error XS9002 Parser: unexpected End of Statement, are you missing a token

2
Begin Namespace NameSpaceOfMainProgram
Function something As Void
[DllImport("ace32.dll", CharSet := CharSet.Ansi)]
Return Nil
End Namespace

-->Error XS9002 Parser: unexpected CRLF, are you missing a token ? (on [DLL import line);

3 Same but then with a ; ([DllImport("ace32.dll", CharSet := CharSet.Ansi)]; )
-->Error XS9002 Parser: unexpected input '[DllImport("ace32.dll", CharSet := CharSet.Ansi)];CRLFReturn'

4

Begin Namespace CheckMail
[DllImport("ace32.dll", CharSet := CharSet.Ansi)];
Function something As Void
Return Nil
End Namespace

+ adding every #using I could find:

then the added program compiles but I still get:

Error XS0103 The name 'AdsConnect60' does not exist in the current context iConnectMailReader

Note: In C# I can solve errors of missing usings with Ctrl + (Quick Actions and Refactorings). I guess that's not easy to implement in X#? What would be the best way to find which #using is required for a keyword? Without all my #usings DLLImport fails (errors mentions DLLImportAttribute and CharSet as missing if I ommit the #usings) but the help does not tell me which #using I would need.

Dick
User avatar
robert
Posts: 4265
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

dbServer access in Bandol RC 2 & some other issues

Post by robert »

Dick,
- create a new, empty file
- type the following code

Code: Select all

USING System
USING System.Runtime.InteropServices

DllImport("ace32.dll", CharSet := CharSet.Ansi)];
FUNCTION AdsConnect60(pucServerPath AS STRING , usServerTypes AS WORD, ;
pucUserName AS STRING , pucPassword AS STRING , ulOptions AS DWORD, phConnect OUT IntPtr ) AS DWORD
And then in your code you can call AdsConnect60()

Explanation:
- The Function statement defines the parameters and return type. There is no body because this function is 'External'
- The [DllImport...] attribute tells the .Net runtime that this function is in an external DLL "ace32.dll" and that the string parameters should be converted to Ansi

Note:
You could also use the _DLL FUNCTION syntax but then it is more difficult to tell the .Net runtime how to handle strings.

Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
ic2
Posts: 1805
Joined: Sun Feb 28, 2016 11:30 pm
Location: Holland

dbServer access in Bandol RC 2 & some other issues

Post by ic2 »

Hello Robert,

I've done exactly what you wrote, pasted your code instead of the default code found in the new empty code file and this is what get on the DLLImport line:

Error XS9002 Parser: unexpected input 'DllImport'

Documentation for Error XS9002 is limited to:

Parser: {0}



Dick
Jamal
Posts: 315
Joined: Mon Jul 03, 2017 7:02 pm

dbServer access in Bandol RC 2 & some other issues

Post by Jamal »

Dick,

I think the left most [ is missing. It should be:

Code: Select all

[DllImport("ace32.dll", CharSet := CharSet.Ansi)];
Jamal
ic2
Posts: 1805
Joined: Sun Feb 28, 2016 11:30 pm
Location: Holland

dbServer access in Bandol RC 2 & some other issues

Post by ic2 »

I think the left most [ is missing. It should be:
Hello Jamal,

Ahh.. You are right, thanks. I just copied and pasted it. Should have seen this myself ;)

I will have to add AdsDisconnect as well but then it may work - let you all know.

Dick
ic2
Posts: 1805
Joined: Sun Feb 28, 2016 11:30 pm
Location: Holland

dbServer access in Bandol RC 2 & some other issues

Post by ic2 »

Not sure why this is posted in the Welcome forum. I did select Product from the subscriber forum. I'll continue it there.

Dick
User avatar
robert
Posts: 4265
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

dbServer access in Bandol RC 2 & some other issues

Post by robert »

Dick,
I moved the message to the product forum

Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
Post Reply