function FindControlX(Handle: HWnd): TWinControl;
  var
    OwningProcessx: DWORD;
    ControlAtom: TAtom;
    ControlAtomString: string;
    RM_GetObjectInstance: DWORD;
  BEGIN
    Result := nil;
    if (Handle <> 0) and (GetWindowThreadProcessID(Handle, OwningProcessx) <> 0) and
          (OwningProcessx  = GetCurrentProcessId) then //   都进行了判断调用进程ID是否为Handle所在进程
    begin
      ////
      ControlAtomString := Format( 'ControlOfs%.8X%.8X', [GetWindowLong(Handle, GWL_HINSTANCE), GetCurrentThreadID]);
      ControlAtom := GlobalAddAtom(PChar(ControlAtomString));
      RM_GetObjectInstance := RegisterWindowMessage(PChar(ControlAtomString));
      ////
      if GlobalFindAtom(PChar(ControlAtomString)) = ControlAtom then
      begin
        Result := Pointer(GetProp(Handle, MakeIntAtom(ControlAtom)));
      end
      else
        Result := Pointer(SendMessage(Handle, RM_GetObjectInstance, 0, 0));
      GlobalDeleteAtom(ControlAtom);
    end
  END;
procedure TSDIAppForm.Button1Click(Sender: TObject);
var
  PropCount: Integer;
  handle: HWnd;
  p: Pointer;
  ControlAtom: TAtom;
  ControlAtomString: string;
  box: TcxComboBox;
  control: TWinControl;
  propList: PPropList;
  i : Integer;
  buf:String;
  pp:PPropInfo;
  f:TextFile;
begin
  handle := cxComboBox1.Handle;  box := TcxComboBox(FindControlX(handle));  //PropCount := GetTypeData(box.ClassInfo).PropCount;
  //GetPropList(box.ClassInfo,propList);
 // buf := '';
  //AssignFile(f,'a.txt');
  //rewrite(f);
  //for i :=0 to PropCount do
  //begin
  //  buf := '';
   // buf := buf + propList[i].Name;
   // Writeln(f,buf);
   // showmessage(buf);
 // end;
  //closefile(f);
  showmessage(box.Properties.Items[0]);
end;以上程序代码可以在窗体程序中正常运行,,拿到DLL不能正常运行,
这是为什么呢???
DLL中的代码:
 function FindControlX(Handle: HWnd): TWinControl;
  var
    OwningProcessx: DWORD;
    ControlAtom: TAtom;
    ControlAtomString: string;
  BEGIN
    Result := nil;
    if (Handle <> 0) and (GetWindowThreadProcessID(Handle, OwningProcessx) <> 0) and
          (OwningProcessx  = GetCurrentProcessId) then //   都进行了判断调用进程ID是否为Handle所在进程
    begin
      ////
      ControlAtomString := Format( 'ControlOfs%.8X%.8X', [GetWindowLong(Handle, GWL_HINSTANCE), GetCurrentThreadID]);
      ControlAtom := GlobalAddAtom(PChar(ControlAtomString));
      RM_GetObjectInstance := RegisterWindowMessage(PChar(ControlAtomString));
      ////
      if GlobalFindAtom(PChar(ControlAtomString)) = ControlAtom then
      begin
        Result := Pointer(GetProp(Handle, MakeIntAtom(ControlAtom)));
      end
      else
        Result := Pointer(SendMessage(Handle, RM_GetObjectInstance, 0, 0));
      GlobalDeleteAtom(ControlAtom);
    end
  END;
function TcxCB_GetSelectedString(Handle: HWnd; Buffer: String): Integer;
  var
    index: Integer;
    box: TcxComboBox;
  begin
    Result := -1;
    try
      box := TcxComboBox(FindControlX(Handle));
      if (box <> nil) then
      begin
        //box.Assign(ctrl);
        //TcxComboBox(Pointer(ctrl)).SelectedItem;
        //index := box.SelectedItem;
        //box.Text := 'ok';
        box.Properties.Items[0];
        DebugMsg('ok');
        Result := -1;
      end;
    except
      on E: Exception do
        DebugMsg(E.Message);
      end;
  end;