• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

using .net object

New Here ,
Apr 20, 2011 Apr 20, 2011

Copy link to clipboard

Copied

Hi,

Im not a CF programmer so please excuse my ignorance, Im trying to help my CF programmer who is having trouble talking to a .net DLL.

We seem to be able to reference anything that is just a plain method no problem - the issue comes when we expect the method to return a value.

If we just call a method to do something it works fine - if we call a method that returns a value, it throws an error saying that the method does not exist?

so we create an object - works fine

<cfset obj2 = createobject(".net, "CLASS", "PATH to dll")>

run the method that doesn't return anything - works fine

<cfset str = obj2.method("var","var","var")>

but how do we get a method that returns a value?

i.e. we want to set the variable result to be the return value from obj2.returningmethod with 3 parameters

<cfset result - obj2.returningmethod("var","var","var")>

can anyone help or point out what we are doing wrong?

Thanks

TOPICS
Advanced techniques

Views

1.7K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 20, 2011 Apr 20, 2011

Copy link to clipboard

Copied

but how do we get a method that returns a value?

Just like you said:

<cfset str = obj2.method("var","var","var")>

run the method that doesn't return anything - works fine

<cfset str = obj2.method("var","var","var")>

No.  That's be:

<cfset obj2.method("var", "var", "var")>

If it doesn't return a value, then don't attempt to stick the value that isn't being returned into a variable 😉

can anyone help or point out what we are doing wrong?

You're over-complicating things in your head.  A function call is a function call: it doesn't matter whether the function is a CFC method, a Java object method, a .net object method, or a built-in CF function, the syntax is always the same:

<cfset theResult = theFunction(theArguments)>

--

Adam

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 20, 2011 Apr 20, 2011

Copy link to clipboard

Copied

Adam,

thanks for clearing that up - its kind of what we thought.

Do you have any ideas why would be getting the method could not be found error? It only seems to be the case for those methods that return values?

We have looked inside the DLL and checked the type the method is expecting - but it just will not run if it has a return value.

Are we missing something simple again?

thanks

Aidan

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 20, 2011 Apr 20, 2011

Copy link to clipboard

Copied

What is the EXACT error message (down to where the stack-trace starts), and what is the EXACT code you are running that causes it.

--

Adam

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 20, 2011 Apr 20, 2011

Copy link to clipboard

Copied

CODE:

<cfset obj2 = createobject(".net", "PWDGENUTILLib.SEAuth

enticationClass", "c:\program files\microsoft SDKs\Wind

ows\v6.1\PWDGENUTILLib.dll")>

<cfset str = StructNew()>

<cfset str = obj2.Authenticate(domain, user, pass)>

ERROR:

the Authenticate method was not found. Either there are no methods with the specified name and arguement types or the Authenticate method is overloaded with arguements that ColdFusion cannot decifer reliably. ColdFusion found 0 methods that match the provided arguements. If this is a Java object and you verify that the method exists, use the javacast function to reduce ambiguity.

the DLL method is listed as:

method Authenticate : void(string,string,string,object&)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Apr 20, 2011 Apr 20, 2011

Copy link to clipboard

Copied

<cfset str = obj2.Authenticate(domain, user, pass)>

void(string,string,string,object&)

Maybe the forum mangled your post .. but it looks like that method has four parameters, not three. Also, is the return type actually "void" ie nothing?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Apr 20, 2011 Apr 20, 2011

Copy link to clipboard

Copied

+1

I've never really had to use .NET objects from within CF, but almost certainly when it says "the method is not found" what it *actually* means is "the method matching the signature you supplied". Therefore method Authenticate(string, string, string) is completely different from the method Authenticate(string, string, string, ref object).

And yes, as pointed out your method clearly returns void so I'm not sure what you expect it to return.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 21, 2011 Apr 21, 2011

Copy link to clipboard

Copied

Hmmmm.

we used to use this DLL as a COM object but have just gone to CF9 on an x64 hardware and it doesn't like it - hence having to go to .net

the manufacturers of the DLL state that all functionality is the same as the COM object.

The com object was called as follows:

<cfset obj2 = createobject("com", "pwdgenutil.SEAuthentication")>

<cfset str = StructNew()>

<cfset str = StructInsert(str, 1, obj2.Authenticate(domain, user, pass, "answer"), "YES")>

<cfif answer is "NO">

blah blah blah

If we could get the COM object working on the x64 it would clear up alot of issues - but this is a bug id 80973 (http://cfbugs.adobe.com/cfbugreport/flexbugui/cfbugtracker/main.html#bugId=80973)

does this shed any more light?

Thakns guys - we seem to be getting nearer to an answer - or atleast a better understanding of what is going off

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 21, 2011 Apr 21, 2011

Copy link to clipboard

Copied

<cfset str = obj2.Authenticate(domain, user, pass)>

void(string,string,string,object&)

Maybe the forum mangled your post .. but it looks like that method has four parameters, not three. Also, is the return type actually "void" ie nothing?

Bingo.

So the error message was on the money, really:

Either there are no methods with the specified name and arguement types

--

Adam

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 21, 2011 Apr 21, 2011

Copy link to clipboard

Copied

so it needs 4 parameters? - if so what is the 4th type?

Sorry - it might seem simple and blatently obvious - but this is beyond my skill level!

Really appreciate your help on this one!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 21, 2011 Apr 21, 2011

Copy link to clipboard

Copied

From your own earlier post:

the DLL method is listed as:

method Authenticate : void(string,string,string,object&)

So that's an object reference.  What sort of object?  Dunno.  And I imagine "any old object" won't actually do 😉

Consult the docs for the DLL.

--

Adam

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 21, 2011 Apr 21, 2011

Copy link to clipboard

Copied

hmm,

the new DLL isn't supported (as usual).

but looking into it you see the following:

.method public hidebysig newslot virtual

instance void Authenticate([in] strin marshal ( bstr) strDomain), [in] string marshal ( bstr) strUserName,[in] string marshal ( bstr) strPassword, [out] object& marshal ( struct) vAuthenticated)

runtime managed internalcall

does this mean its a structure of some sort?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Apr 21, 2011 Apr 21, 2011

Copy link to clipboard

Copied

Try passing in a null as the last parameter:

javaCast("null", "")

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 21, 2011 Apr 21, 2011

Copy link to clipboard

Copied

well the NULL parameter has gotten rid of the authenticaet method does not exist message.

now I am getting error tag context

<cfset answer = obj2.Authenticate(JavaCast("string", "#domain#"), JavaCast("string", "#user#"), JavaCast("string", "#password#"), JavaCast("null", ""))>

answer is setup as a struct and when I dump the contents of answer - nothing is there

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Apr 21, 2011 Apr 21, 2011

Copy link to clipboard

Copied

That's because (as has been mentioned about three times now) your method *does not return anything*

method Authenticate : void(string,string,string,object&)

Void = nothing = nada

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 21, 2011 Apr 21, 2011

Copy link to clipboard

Copied

it should return either a yes or no.

looking at the other methods in there we have managed to use method BulkGeneratePasswords : void (int32,int32,string)

by using the following code <cfset obj2.BulkGeneratePasswords(JavaCast("int", 9), JavaCast("int", 3), "E:\test.txt)> and the file is generated ok but these parameters are all passed in with nothing being returned.

its got to do something - otherwise it would be pointless

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Apr 21, 2011 Apr 21, 2011

Copy link to clipboard

Copied

it should return either a yes or no.

But it clearly returns void - the documentation and underlying IL code say so.

<cfset obj2.BulkGeneratePasswords(JavaCast("int", 9), JavaCast("int", 3), "E:\test.txt)> and the file is generated ok but these parameters are all passed in with nothing being returned.

But that's different - that method appears to be there for the purpose of creating a file on disk, which it does. A method does not have to return anything in order to have succeeded.

Just because a method doesn't return anything doesn't mean it hasn't worked - it simply means the programmer has decided it doesn't need to return anything. If the authenticate() method returns null, I'd expect to see some kind of isAuthenticated() method or property on the class which you would call afterwards. Or for the authenticate() method to throw an exception on failure rather than returning false.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 21, 2011 Apr 21, 2011

Copy link to clipboard

Copied

theres a ProcessCredentials method with exactly the same parameters and types as the authenticate.

We never used this when we were doing this as part of the COM object - and as it has the same parameters Im a bit lost as to what to do next.

The authenticate should take the domain , username and password and say yes or no if the details are good or bad.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Apr 21, 2011 Apr 21, 2011

Copy link to clipboard

Copied

The authenticate should take the domain , username and password and say yes or no if the details are good or bad.

I hear you, but the fact remains that it simply doesn't. You'll have to check the documentation or get in touch with whoever wrote the dll to ask them what you're meant to do. It's not impossible that it's a bug in their dll they don't know about.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 12, 2011 May 12, 2011

Copy link to clipboard

Copied

LATEST

So I've been back to the developer and they informed me of the following:

the authenticate method takes 3 string parameters and a variable passed by reference (the answer)

they provided me with a small exe that does what the method should do in C#.NET and according to them the type is a .net object that they then convert it to a string.

So how do we pass in this parameter by reference in CF? and then manipulate the response (should be either true or false)

thanks

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation