Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DLL Works from Visual Studio, but not IIS

Status
Not open for further replies.

djjd47130

Programmer
Nov 1, 2010
480
0
0
US
I have a website built in Visual Studio 2010 in ASP.NET using C#. I've made a DLL in Delphi to be used by this website. The DLL includes some simple functions in StdCall. This has always worked before, but now for some reason I have the most peculiar problem. When I run the website project directly from Visual Studio, everything works perfectly as expected. It opens the DLL and call the functions properly. However, when I'm viewing the website through IIS, I get the following error message when I try to access the DLL:

An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)

The DLL is in fact in the bin folder, proper access is set, I've restarted IIS, the application pool, and the entire computer its self, to make sure the application was started properly. Nothing seems to work. Here's how I read the DLL:

Code:
        [DllImport("JDWeb.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
        public static extern string GetUserFirstName(string ConnectionString, string UserName);





        public static string UserFirstName(string UserName)
        {
            return GetUserFirstName(ConfigurationManager.AppSettings["JDDatabase"].ToString(), UserName);    
        }

The contents of the DLL look like this:

Code:
function GetUserFirstName(ConnectionString: PChar; UserName: PChar): PChar; stdcall; 
var
  Q: TADOQuery;  
  cUserName: String;
  R: String;
begin
  Result:= '';
  cUserName:= UserName;
  Q:= TADOQuery.Create(nil);
  try
    try
      Q.ConnectionString:= ConnectionString;
      Q.SQL.Text:= 'select * from [User_Profiles] where [UserName] = '''+ cUserName + '''';
      Q.Open;
        if not Q.IsEmpty then begin
          Q.First;
          R:= Q.FieldByName('FirstName').AsString;
          Result:= PChar(R);
        end;
      Q.Close;
    except
      on e: exception do begin
      end;
    end;
  finally
    Q.Free;
  end;
end;

...

exports
  GetUserFirstName;



JD Solutions
 
JD Solutions,

Not sure if this will offer any help but you could try the following:
1. Make sure your references are set correctly in the project.
2. In IIS set the application pool to enable 32 bit applicaitons.
2. In the project properties, change target cpu to any cpu and/or also try x86 only if applicable.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top